fix: send correct field names when updating book progress

This commit is contained in:
2026-08-10 23:58:42 -04:00
parent 3091cc879d
commit 3ae3dcb0d0
3 changed files with 11 additions and 28 deletions
-14
View File
@@ -3,7 +3,6 @@ import { error } from '@sveltejs/kit';
import { import {
bookCoverUpload, bookCoverUpload,
booksUpload, booksUpload,
bookIdsSchema,
bookQuerySchema, bookQuerySchema,
deleteBookFilesSchema, deleteBookFilesSchema,
deleteBooksSchema, 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);
}
});
+5 -8
View File
@@ -77,27 +77,24 @@ export const deleteBooksSchema = z.object({
library_id: stringCoerce library_id: stringCoerce
}); });
export const bookIdsSchema = z.object({
book_ids: stringArrayCoerce // TODO Could also set minimum length of 1
});
export const deleteBookFilesSchema = z.object({ export const deleteBookFilesSchema = z.object({
book_id: stringCoerce, book_id: stringCoerce,
file_ids: stringArrayCoerce, file_ids: stringArrayCoerce,
delete_files: z.boolean() delete_files: z.boolean()
}); });
// Mirrors BookProgressCreate in backend/src/chitai/schemas/book.py
export const updateBookProgressSchema = z.object({ export const updateBookProgressSchema = z.object({
book_ids: stringArrayCoerce, book_ids: stringArrayCoerce,
progress: number().min(0).max(1), percentage: number().min(0).max(1),
completed: z.boolean().optional().default(false), completed: z.boolean().optional().default(false),
epub_loc: z.string().optional(), epub_cfi: z.string().optional(),
pdf_loc: z.string().optional() epub_xpointer: z.string().optional(),
pdf_page: z.number().int().optional()
}); });
export type BookQuery = z.infer<typeof bookQuerySchema>; export type BookQuery = z.infer<typeof bookQuerySchema>;
export type BookEditMetadata = z.infer<typeof editBookMetadataSchema>; export type BookEditMetadata = z.infer<typeof editBookMetadataSchema>;
export type DeleteBook = z.infer<typeof deleteBooksSchema>; export type DeleteBook = z.infer<typeof deleteBooksSchema>;
export type BookIds = z.infer<typeof bookIdsSchema>;
export type DeleteBookFiles = z.infer<typeof deleteBookFilesSchema>; export type DeleteBookFiles = z.infer<typeof deleteBookFilesSchema>;
export type UpdateBookProgress = z.infer<typeof updateBookProgressSchema>; export type UpdateBookProgress = z.infer<typeof updateBookProgressSchema>;
@@ -101,12 +101,12 @@ export class BookOperationsState {
async markBooksAsComplete(bookIds: string[] | number[]) { async markBooksAsComplete(bookIds: string[] | number[]) {
try { try {
await this.updateBookProgress(bookIds, { await this.updateBookProgress(bookIds, {
progress: 1, percentage: 1,
completed: true completed: true
}); });
if (bookIds.length > 1) toast.success('Book marked as complete!'); if (bookIds.length > 1) toast.success(`${bookIds.length} books marked as complete!`);
else toast.success(`${bookIds.length} books marked as complete!`); else toast.success('Book marked as complete!');
// Get fresh data // Get fresh data
await this.reload(); await this.reload();
@@ -119,12 +119,12 @@ export class BookOperationsState {
async markBooksAsIncomplete(bookIds: number[]) { async markBooksAsIncomplete(bookIds: number[]) {
try { try {
await this.updateBookProgress(bookIds, { await this.updateBookProgress(bookIds, {
progress: 0, percentage: 0,
completed: false completed: false
}); });
if (bookIds.length > 1) toast.success('Book progress reset!'); if (bookIds.length > 1) toast.success(`Reset progress for ${bookIds.length} books!`);
else toast.success(`Reset progress for ${bookIds.length} books!`); else toast.success('Book progress reset!');
// get fresh data // get fresh data
await this.reload(); await this.reload();