Book form: can now edit an existing book

This commit is contained in:
2026-04-01 00:34:09 +02:00
parent bcde39d51d
commit 8d97d00e93
11 changed files with 297 additions and 85 deletions

View File

@@ -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))
}