Extend repository methods and synchronization logic with existence checks for books, chapters, characters, and related entities
- Add methods to verify the existence of acts, plot points, incidents, worlds, characters, locations, and their sub-elements in repositories. - Update `syncBookFromServerToClient` to integrate existence checks with insert or update logic. - Enhance multilingual error handling across repository methods.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {Database, RunResult, SQLiteValue} from 'node-sqlite3-wasm';
|
||||
import {Database, QueryResult, RunResult, SQLiteValue} from 'node-sqlite3-wasm';
|
||||
import System from "../System.js";
|
||||
|
||||
export interface ChapterContentQueryResult extends Record<string, SQLiteValue>{
|
||||
@@ -410,4 +410,35 @@ export default class ChapterRepo{
|
||||
}
|
||||
}
|
||||
}
|
||||
static isChapterExist(userId: string, chapter_id: string, lang: "fr" | "en"): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: QueryResult | null = db.get('SELECT 1 FROM book_chapters WHERE chapter_id=? AND author_id=?', [chapter_id, userId]) || null;
|
||||
return result !== null;
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
console.error(`DB Error: ${e.message}`);
|
||||
throw new Error(lang === 'fr' ? `Impossible de vérifier l'existence du chapitre.` : `Unable to check chapter existence.`);
|
||||
} else {
|
||||
console.error("An unknown error occurred.");
|
||||
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static isChapterInfoExist(userId: string, chapter_id: string, lang: "fr" | "en"): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: QueryResult | null = db.get('SELECT 1 FROM `book_chapter_infos` WHERE `chapter_id`=? AND `author_id`=?', [chapter_id, userId]) || null;
|
||||
return result !== null;
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
console.error(`DB Error: ${e.message}`);
|
||||
throw new Error(lang === 'fr' ? `Impossible de vérifier l'existence des informations du chapitre.` : `Unable to check chapter info existence.`);
|
||||
} else {
|
||||
console.error("An unknown error occurred.");
|
||||
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user