chore: move files to frontend
This commit is contained in:
1 parent
d45d7f92fb
commit
7414ca10b3
137 files changed
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import { fetchURL, fetchJSON } from './utils'
|
||||
|
||||
export async function getAll () {
|
||||
return fetchJSON(`/api/users`, {})
|
||||
}
|
||||
|
||||
export async function get (id) {
|
||||
return fetchJSON(`/api/users/${id}`, {})
|
||||
}
|
||||
|
||||
export async function create (user) {
|
||||
const res = await fetchURL(`/api/users`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
what: 'user',
|
||||
which: [],
|
||||
data: user
|
||||
})
|
||||
})
|
||||
|
||||
if (res.status === 201) {
|
||||
return res.headers.get('Location')
|
||||
} else {
|
||||
throw new Error(res.status)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export async function update (user, which = ['all']) {
|
||||
const res = await fetchURL(`/api/users/${user.id}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({
|
||||
what: 'user',
|
||||
which: which,
|
||||
data: user
|
||||
})
|
||||
})
|
||||
|
||||
if (res.status !== 200) {
|
||||
throw new Error(res.status)
|
||||
}
|
||||
}
|
||||
|
||||
export async function remove (id) {
|
||||
const res = await fetchURL(`/api/users/${id}`, {
|
||||
method: 'DELETE'
|
||||
})
|
||||
|
||||
if (res.status !== 200) {
|
||||
throw new Error(res.status)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user