42 lines
928 B
TypeScript
42 lines
928 B
TypeScript
|
import { reactive } from 'vue'
|
||
|
|
||
|
export const groups_store = reactive({
|
||
|
groups: [],
|
||
|
})
|
||
|
|
||
|
export function update_groups() {
|
||
|
fetch('http://localhost:31337/get/groups', {
|
||
|
credentials: 'include',
|
||
|
})
|
||
|
.then((res) => {
|
||
|
res
|
||
|
.json()
|
||
|
.then((groupsjson) => {
|
||
|
groups_store.groups = groupsjson.groups
|
||
|
})
|
||
|
.catch(() => {})
|
||
|
})
|
||
|
.catch(() => {})
|
||
|
}
|
||
|
|
||
|
export function add_group(group: string) {
|
||
|
fetch('http://localhost:31337/post/group?name=' + group, {
|
||
|
credentials: 'include',
|
||
|
method: 'POST',
|
||
|
body: JSON.stringify({ name: group }),
|
||
|
headers: {
|
||
|
'Content-Type': 'application/json',
|
||
|
},
|
||
|
})
|
||
|
.then((res) => {
|
||
|
if (res.status === 400) {
|
||
|
console.log('Group submitted is invalid.')
|
||
|
} else if (res.status === 401) {
|
||
|
console.log("You aren't logged in.")
|
||
|
} else {
|
||
|
update_groups()
|
||
|
}
|
||
|
})
|
||
|
.catch(() => {})
|
||
|
}
|