fix: send correct field names when updating book progress
This commit is contained in:
@@ -3,7 +3,6 @@ import { error } from '@sveltejs/kit';
|
||||
import {
|
||||
bookCoverUpload,
|
||||
booksUpload,
|
||||
bookIdsSchema,
|
||||
bookQuerySchema,
|
||||
deleteBookFilesSchema,
|
||||
deleteBooksSchema,
|
||||
@@ -149,16 +148,3 @@ export const updateBookProgress = command(
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export const markBooksAsComplete = command(bookIdsSchema, async (data) => {
|
||||
const { locals } = getRequestEvent();
|
||||
|
||||
const params = createQueryParams(data);
|
||||
|
||||
const response = await locals.api.post(`/books/completed?${params.toString()}`, {});
|
||||
|
||||
if (!response.ok) {
|
||||
const message = await response.text();
|
||||
error(response.status, message);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -77,27 +77,24 @@ export const deleteBooksSchema = z.object({
|
||||
library_id: stringCoerce
|
||||
});
|
||||
|
||||
export const bookIdsSchema = z.object({
|
||||
book_ids: stringArrayCoerce // TODO Could also set minimum length of 1
|
||||
});
|
||||
|
||||
export const deleteBookFilesSchema = z.object({
|
||||
book_id: stringCoerce,
|
||||
file_ids: stringArrayCoerce,
|
||||
delete_files: z.boolean()
|
||||
});
|
||||
|
||||
// Mirrors BookProgressCreate in backend/src/chitai/schemas/book.py
|
||||
export const updateBookProgressSchema = z.object({
|
||||
book_ids: stringArrayCoerce,
|
||||
progress: number().min(0).max(1),
|
||||
percentage: number().min(0).max(1),
|
||||
completed: z.boolean().optional().default(false),
|
||||
epub_loc: z.string().optional(),
|
||||
pdf_loc: z.string().optional()
|
||||
epub_cfi: z.string().optional(),
|
||||
epub_xpointer: z.string().optional(),
|
||||
pdf_page: z.number().int().optional()
|
||||
});
|
||||
|
||||
export type BookQuery = z.infer<typeof bookQuerySchema>;
|
||||
export type BookEditMetadata = z.infer<typeof editBookMetadataSchema>;
|
||||
export type DeleteBook = z.infer<typeof deleteBooksSchema>;
|
||||
export type BookIds = z.infer<typeof bookIdsSchema>;
|
||||
export type DeleteBookFiles = z.infer<typeof deleteBookFilesSchema>;
|
||||
export type UpdateBookProgress = z.infer<typeof updateBookProgressSchema>;
|
||||
|
||||
@@ -101,12 +101,12 @@ export class BookOperationsState {
|
||||
async markBooksAsComplete(bookIds: string[] | number[]) {
|
||||
try {
|
||||
await this.updateBookProgress(bookIds, {
|
||||
progress: 1,
|
||||
percentage: 1,
|
||||
completed: true
|
||||
});
|
||||
|
||||
if (bookIds.length > 1) toast.success('Book marked as complete!');
|
||||
else toast.success(`${bookIds.length} books marked as complete!`);
|
||||
if (bookIds.length > 1) toast.success(`${bookIds.length} books marked as complete!`);
|
||||
else toast.success('Book marked as complete!');
|
||||
|
||||
// Get fresh data
|
||||
await this.reload();
|
||||
@@ -119,12 +119,12 @@ export class BookOperationsState {
|
||||
async markBooksAsIncomplete(bookIds: number[]) {
|
||||
try {
|
||||
await this.updateBookProgress(bookIds, {
|
||||
progress: 0,
|
||||
percentage: 0,
|
||||
completed: false
|
||||
});
|
||||
|
||||
if (bookIds.length > 1) toast.success('Book progress reset!');
|
||||
else toast.success(`Reset progress for ${bookIds.length} books!`);
|
||||
if (bookIds.length > 1) toast.success(`Reset progress for ${bookIds.length} books!`);
|
||||
else toast.success('Book progress reset!');
|
||||
|
||||
// get fresh data
|
||||
await this.reload();
|
||||
|
||||
Reference in New Issue
Block a user