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 CharacterResult extends Record<string, SQLiteValue> {
|
||||
@@ -180,4 +180,35 @@ export default class CharacterRepo {
|
||||
}
|
||||
}
|
||||
}
|
||||
static isCharacterExist(userId: string, characterId: string,lang: "fr" | "en"): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: QueryResult | null = db.get('SELECT 1 FROM `book_characters` WHERE `character_id`=? AND `user_id`=?', [characterId, 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 personnage.` : `Unable to check character existence.`);
|
||||
} else {
|
||||
console.error("An unknown error occurred.");
|
||||
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static isCharacterAttributeExist(userId: string, characterAttributeId: string,lang: "fr" | "en"): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: QueryResult | null = db.get('SELECT 1 FROM `book_characters_attributes` WHERE `attr_id`=? AND `user_id`=?', [characterAttributeId, 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 de l'attribut du personnage.` : `Unable to check character attribute 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