Book form: can now edit an existing book
This commit is contained in:
@@ -18,28 +18,34 @@ export function getImagePathOrGivenDefault(path, defaultpath) {
|
||||
}
|
||||
}
|
||||
|
||||
function useFetch(data, error, url) {
|
||||
function userFetch(url) {
|
||||
const { user } = useAuthStore()
|
||||
|
||||
if (user != null) {
|
||||
fetch(url, {
|
||||
return fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + user.token,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.status === 401) {
|
||||
const authStore = useAuthStore()
|
||||
authStore.logout()
|
||||
}
|
||||
return res.json()
|
||||
})
|
||||
.then((json) => (data.value = json))
|
||||
.catch((err) => (error.value = err))
|
||||
} else {
|
||||
return Promise.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
function useFetch(data, error, url) {
|
||||
userFetch(url)
|
||||
.then((res) => {
|
||||
if (res.status === 401) {
|
||||
const authStore = useAuthStore()
|
||||
authStore.logout()
|
||||
}
|
||||
return res.json()
|
||||
})
|
||||
.then((json) => (data.value = json))
|
||||
.catch((err) => (error.value = err))
|
||||
}
|
||||
|
||||
export async function getAppInfo(appInfo, appInfoErr) {
|
||||
return fetch('/ws/appinfo', {
|
||||
method: 'GET',
|
||||
@@ -98,6 +104,10 @@ export function getBook(data, error, id) {
|
||||
return useFetch(data, error, '/ws/book/' + id)
|
||||
}
|
||||
|
||||
export function getBookCall(id) {
|
||||
return userFetch('/ws/book/' + id)
|
||||
}
|
||||
|
||||
export function postBook(book) {
|
||||
return genericPayloadCall('/ws/book', book.value, 'POST')
|
||||
}
|
||||
@@ -106,6 +116,10 @@ export async function postImportBook(id, language) {
|
||||
return genericPayloadCall('/ws/importbook', { inventaireid: id, lang: language }, 'POST')
|
||||
}
|
||||
|
||||
export function putBook(id, book) {
|
||||
return genericPayloadCall('/ws/book/edit/' + id, book.value, 'PUT')
|
||||
}
|
||||
|
||||
export async function putReadBook(bookId) {
|
||||
return putEndReadDate(bookId, new Date().toISOString().slice(0, 10))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user