Refactor Book model and related components for consistent property naming

- Replaced `id` with `bookId` in `BookProps` and updated corresponding references.
- Added `tools` property to book-related components for tool management.
- Removed unused `books` property from `User` model.
- Added debug logs in `deleteBook` and `BookList` for troubleshooting.
This commit is contained in:
natreex
2026-01-15 17:22:59 -05:00
parent 3d4feaa680
commit ac968b7764
5 changed files with 7 additions and 12 deletions

View File

@@ -78,6 +78,7 @@ export default function ScribeControllerBar() {
desiredWordCount: response.desiredWordCount, desiredWordCount: response.desiredWordCount,
totalWordCount: response.desiredWordCount, totalWordCount: response.desiredWordCount,
quillsenseEnabled: response.quillsenseEnabled, quillsenseEnabled: response.quillsenseEnabled,
tools: response?.tools,
}); });
} catch (e: unknown) { } catch (e: unknown) {
if (e instanceof Error) { if (e instanceof Error) {

View File

@@ -161,6 +161,7 @@ export default function BookList() {
const localBooks: BookProps[] = await window.electron.invoke<BookProps[]>('db:book:books'); const localBooks: BookProps[] = await window.electron.invoke<BookProps[]>('db:book:books');
bookResponse = localBooks.map((book: BookProps): BookProps & { itIsLocal: boolean } => ({ ...book, itIsLocal: true })); bookResponse = localBooks.map((book: BookProps): BookProps & { itIsLocal: boolean } => ({ ...book, itIsLocal: true }));
} }
console.log(bookResponse);
if (bookResponse) { if (bookResponse) {
const booksByType: Record<string, BookProps[]> = bookResponse.reduce((groups: Record<string, BookProps[]>, book: BookProps): Record<string, BookProps[]> => { const booksByType: Record<string, BookProps[]> = bookResponse.reduce((groups: Record<string, BookProps[]>, book: BookProps): Record<string, BookProps[]> => {
const imageDataUrl: string = book.coverImage ? 'data:image/jpeg;base64,' + book.coverImage : ''; const imageDataUrl: string = book.coverImage ? 'data:image/jpeg;base64,' + book.coverImage : '';
@@ -267,6 +268,7 @@ export default function BookList() {
localBook: localBookOnly, localBook: localBookOnly,
coverImage: bookResponse?.coverImage ? 'data:image/jpeg;base64,' + bookResponse.coverImage : '', coverImage: bookResponse?.coverImage ? 'data:image/jpeg;base64,' + bookResponse.coverImage : '',
quillsenseEnabled: bookResponse?.quillsenseEnabled, quillsenseEnabled: bookResponse?.quillsenseEnabled,
tools: bookResponse?.tools,
}); });
} }
} catch (e: unknown) { } catch (e: unknown) {

View File

@@ -41,7 +41,7 @@ export interface SyncedBookTools {
} }
export interface BookProps { export interface BookProps {
id: string; bookId: string;
type: string; type: string;
authorId: string; authorId: string;
title: string; title: string;
@@ -190,7 +190,7 @@ export default class Book {
return await Promise.all( return await Promise.all(
books.map(async (book: BookQuery): Promise<BookProps> => { books.map(async (book: BookQuery): Promise<BookProps> => {
return { return {
id: book.book_id, bookId: book.book_id,
type: book.type, type: book.type,
authorId: book.author_id, authorId: book.author_id,
title: System.decryptDataWithUserKey(book.title, userKey), title: System.decryptDataWithUserKey(book.title, userKey),
@@ -254,7 +254,7 @@ export default class Book {
book.getBookInfos(userId); book.getBookInfos(userId);
const bookTools: BookToolsTable | null = BookRepo.fetchBookTools(userId, bookId, lang); const bookTools: BookToolsTable | null = BookRepo.fetchBookTools(userId, bookId, lang);
return { return {
id: book.getId(), bookId: book.getId(),
type: book.getType(), type: book.getType(),
authorId: book.getAuthorId(), authorId: book.getAuthorId(),
title: book.getTitle(), title: book.getTitle(),

View File

@@ -44,7 +44,6 @@ export interface UserInfoResponse {
groupId: number; groupId: number;
termsAccepted: boolean; termsAccepted: boolean;
guideTour: GuideTour[]; guideTour: GuideTour[];
books: BookSummary[];
} }
/** /**
@@ -105,7 +104,6 @@ export default class User {
public static async returnUserInfos(userId: string): Promise<UserInfoResponse> { public static async returnUserInfos(userId: string): Promise<UserInfoResponse> {
const user: User = new User(userId); const user: User = new User(userId);
await user.getUserInfos(); await user.getUserInfos();
const userBooks: BookProps[] = await Book.getBooks(userId);
const guideTourStatus: GuideTour[] = []; const guideTourStatus: GuideTour[] = [];
return { return {
id: user.getId(), id: user.getId(),
@@ -118,13 +116,6 @@ export default class User {
groupId: user.getGroupId(), groupId: user.getGroupId(),
termsAccepted: user.isTermsAccepted(), termsAccepted: user.isTermsAccepted(),
guideTour: guideTourStatus, guideTour: guideTourStatus,
books: userBooks.map((book: BookProps): BookSummary => {
return {
bookId: book.id,
title: book.title,
subTitle: book.subTitle,
};
})
}; };
} }

View File

@@ -260,6 +260,7 @@ export default class BookRepo {
* @returns true if the deletion was successful * @returns true if the deletion was successful
*/ */
public static deleteBook(userId: string, bookId: string, lang: 'fr' | 'en'): boolean { public static deleteBook(userId: string, bookId: string, lang: 'fr' | 'en'): boolean {
console.log(`Deleting book with ID ${bookId} for user ${userId}`)
try { try {
const db: Database = System.getDb(); const db: Database = System.getDb();
const query: string = 'DELETE FROM erit_books WHERE author_id=? AND book_id=?'; const query: string = 'DELETE FROM erit_books WHERE author_id=? AND book_id=?';