Introduce series management functionality and repository updates
- Added `series-world.repo.ts` to handle database operations related to series worlds and their elements. - Implemented `series-sync.repo.ts` for managing synchronization between books and series. - Expanded `spell.ipc.ts` data models to include `seriesSpellId` for spell synchronization. - Refactored `insertSpellTag` method in `spelltag.repo.ts` for improved error handling and logic clarity.
This commit is contained in:
@@ -54,23 +54,24 @@ export interface CharacterResult extends Record<string, SQLiteValue> {
|
||||
character_id: string;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
nickname: string;
|
||||
age: string;
|
||||
gender: string;
|
||||
species: string;
|
||||
nationality: string;
|
||||
status: string;
|
||||
nickname: string | null;
|
||||
age: string | null;
|
||||
gender: string | null;
|
||||
species: string | null;
|
||||
nationality: string | null;
|
||||
status: string | null;
|
||||
title: string;
|
||||
category: string;
|
||||
image: string;
|
||||
role: string;
|
||||
biography: string;
|
||||
history: string;
|
||||
speech_pattern: string;
|
||||
catchphrase: string;
|
||||
residence: string;
|
||||
notes: string;
|
||||
color: string;
|
||||
speech_pattern: string | null;
|
||||
catchphrase: string | null;
|
||||
residence: string | null;
|
||||
notes: string | null;
|
||||
color: string | null;
|
||||
series_character_id: string | null;
|
||||
}
|
||||
|
||||
export interface AttributeResult extends Record<string, SQLiteValue> {
|
||||
@@ -83,11 +84,22 @@ export interface CompleteCharacterResult extends Record<string, SQLiteValue> {
|
||||
character_id: string;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
nickname: string | null;
|
||||
age: string | null;
|
||||
gender: string | null;
|
||||
species: string | null;
|
||||
nationality: string | null;
|
||||
status: string | null;
|
||||
category: string;
|
||||
title: string;
|
||||
role: string;
|
||||
biography: string;
|
||||
history: string;
|
||||
speech_pattern: string | null;
|
||||
catchphrase: string | null;
|
||||
residence: string | null;
|
||||
notes: string | null;
|
||||
color: string | null;
|
||||
attribute_name: string;
|
||||
attribute_value: string;
|
||||
}
|
||||
@@ -103,7 +115,7 @@ export default class CharacterRepo {
|
||||
public static fetchCharacters(userId: string, bookId: string, lang: 'fr' | 'en' = 'fr'): CharacterResult[] {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const query: string = 'SELECT character_id, first_name, last_name, nickname, age, gender, species, nationality, status, title, category, image, role, biography, history, speech_pattern, catchphrase, residence, notes, color FROM book_characters WHERE book_id=? AND user_id=?';
|
||||
const query: string = 'SELECT character_id, first_name, last_name, nickname, age, gender, species, nationality, status, title, category, image, role, biography, history, speech_pattern, catchphrase, residence, notes, color, series_character_id FROM book_characters WHERE book_id=? AND user_id=?';
|
||||
const params: SQLiteValue[] = [bookId, userId];
|
||||
const characters: CharacterResult[] = db.all(query, params) as CharacterResult[];
|
||||
return characters;
|
||||
@@ -129,46 +141,35 @@ export default class CharacterRepo {
|
||||
*/
|
||||
public static addNewCharacter(userId: string, characterId: string, characterData: {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
nickname: string;
|
||||
age: string;
|
||||
gender: string;
|
||||
species: string;
|
||||
nationality: string;
|
||||
status: string;
|
||||
title: string;
|
||||
category: string;
|
||||
image: string;
|
||||
role: string;
|
||||
biography: string;
|
||||
history: string;
|
||||
speechPattern: string;
|
||||
catchphrase: string;
|
||||
residence: string;
|
||||
notes: string;
|
||||
color: string;
|
||||
}, bookId: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
lastName: string | null;
|
||||
nickname: string | null;
|
||||
age: string | null;
|
||||
gender: string | null;
|
||||
species: string | null;
|
||||
nationality: string | null;
|
||||
status: string | null;
|
||||
title: string | null;
|
||||
category: string | null;
|
||||
image: string | null;
|
||||
role: string | null;
|
||||
biography: string | null;
|
||||
history: string | null;
|
||||
speechPattern: string | null;
|
||||
catchphrase: string | null;
|
||||
residence: string | null;
|
||||
notes: string | null;
|
||||
color: string | null;
|
||||
}, bookId: string, lang: 'fr' | 'en' = 'fr', seriesCharacterId: string | null = null): string {
|
||||
let insertResult: RunResult;
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const query: string = `INSERT INTO book_characters (
|
||||
character_id, book_id, user_id, first_name, last_name, nickname, age, gender, species, nationality, status,
|
||||
category, title, image, role, biography, history, speech_pattern, catchphrase, residence, notes, color, last_update
|
||||
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`;
|
||||
const params: SQLiteValue[] = [
|
||||
characterId, bookId, userId,
|
||||
characterData.firstName, characterData.lastName, characterData.nickname,
|
||||
characterData.age, characterData.gender, characterData.species,
|
||||
characterData.nationality, characterData.status, characterData.category,
|
||||
characterData.title, characterData.image, characterData.role,
|
||||
characterData.biography, characterData.history, characterData.speechPattern,
|
||||
characterData.catchphrase, characterData.residence, characterData.notes,
|
||||
characterData.color, System.timeStampInSeconds()
|
||||
];
|
||||
const insertResult: RunResult = db.run(query, params);
|
||||
if (!insertResult || insertResult.changes === 0) {
|
||||
throw new Error(lang === 'fr' ? `Une erreur s'est produite lors de l'ajout du personnage.` : `Error adding character.`);
|
||||
}
|
||||
return characterId;
|
||||
const query: string = seriesCharacterId
|
||||
? 'INSERT INTO book_characters (character_id, book_id, user_id, first_name, last_name, nickname, age, gender, species, nationality, status, category, title, image, role, biography, history, speech_pattern, catchphrase, residence, notes, color, series_character_id, last_update) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'
|
||||
: 'INSERT INTO book_characters (character_id, book_id, user_id, first_name, last_name, nickname, age, gender, species, nationality, status, category, title, image, role, biography, history, speech_pattern, catchphrase, residence, notes, color, last_update) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
|
||||
const params: SQLiteValue[] = seriesCharacterId
|
||||
? [characterId, bookId, userId, characterData.firstName, characterData.lastName, characterData.nickname, characterData.age, characterData.gender, characterData.species, characterData.nationality, characterData.status, characterData.category, characterData.title, characterData.image, characterData.role, characterData.biography, characterData.history, characterData.speechPattern, characterData.catchphrase, characterData.residence, characterData.notes, characterData.color, seriesCharacterId, System.timeStampInSeconds()]
|
||||
: [characterId, bookId, userId, characterData.firstName, characterData.lastName, characterData.nickname, characterData.age, characterData.gender, characterData.species, characterData.nationality, characterData.status, characterData.category, characterData.title, characterData.image, characterData.role, characterData.biography, characterData.history, characterData.speechPattern, characterData.catchphrase, characterData.residence, characterData.notes, characterData.color, System.timeStampInSeconds()];
|
||||
insertResult = db.run(query, params);
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
console.error(`DB Error: ${error.message}`);
|
||||
@@ -178,6 +179,10 @@ export default class CharacterRepo {
|
||||
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
|
||||
}
|
||||
}
|
||||
if (!insertResult || insertResult.changes === 0) {
|
||||
throw new Error(lang === 'fr' ? `Une erreur s'est produite lors de l'ajout du personnage.` : `Error adding character.`);
|
||||
}
|
||||
return characterId;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,15 +196,12 @@ export default class CharacterRepo {
|
||||
* @returns The attribute ID if successful
|
||||
*/
|
||||
static insertAttribute(attributeId: string, characterId: string, userId: string, type: string, name: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
let insertResult: RunResult;
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const query: string = 'INSERT INTO `book_characters_attributes` (attr_id, character_id, user_id, attribute_name, attribute_value, last_update) VALUES (?,?,?,?,?,?)';
|
||||
const query: string = 'INSERT INTO book_characters_attributes (attr_id, character_id, user_id, attribute_name, attribute_value, last_update) VALUES (?,?,?,?,?,?)';
|
||||
const params: SQLiteValue[] = [attributeId, characterId, userId, type, name, System.timeStampInSeconds()];
|
||||
const insertResult: RunResult = db.run(query, params);
|
||||
if (!insertResult || insertResult.changes === 0) {
|
||||
throw new Error(lang === 'fr' ? `Une erreur s'est produite lors de l'ajout de l'attribut.` : `Error adding attribute.`);
|
||||
}
|
||||
return attributeId;
|
||||
insertResult = db.run(query, params);
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
console.error(`DB Error: ${error.message}`);
|
||||
@@ -209,6 +211,10 @@ export default class CharacterRepo {
|
||||
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
|
||||
}
|
||||
}
|
||||
if (!insertResult || insertResult.changes === 0) {
|
||||
throw new Error(lang === 'fr' ? `Une erreur s'est produite lors de l'ajout de l'attribut.` : `Error adding attribute.`);
|
||||
}
|
||||
return attributeId;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,41 +228,33 @@ export default class CharacterRepo {
|
||||
*/
|
||||
static updateCharacter(userId: string, id: string, characterData: {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
nickname: string;
|
||||
age: string;
|
||||
gender: string;
|
||||
species: string;
|
||||
nationality: string;
|
||||
status: string;
|
||||
title: string;
|
||||
category: string;
|
||||
image: string;
|
||||
role: string;
|
||||
biography: string;
|
||||
history: string;
|
||||
speechPattern: string;
|
||||
catchphrase: string;
|
||||
residence: string;
|
||||
notes: string;
|
||||
color: string;
|
||||
}, lastUpdate: number, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
lastName: string | null;
|
||||
nickname: string | null;
|
||||
age: string | null;
|
||||
gender: string | null;
|
||||
species: string | null;
|
||||
nationality: string | null;
|
||||
status: string | null;
|
||||
title: string | null;
|
||||
category: string | null;
|
||||
image: string | null;
|
||||
role: string | null;
|
||||
biography: string | null;
|
||||
history: string | null;
|
||||
speechPattern: string | null;
|
||||
catchphrase: string | null;
|
||||
residence: string | null;
|
||||
notes: string | null;
|
||||
color: string | null;
|
||||
}, lastUpdate: number, lang: 'fr' | 'en' = 'fr', seriesCharacterId: string | null = null): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const query: string = `UPDATE book_characters SET
|
||||
first_name=?, last_name=?, nickname=?, age=?, gender=?, species=?, nationality=?, status=?,
|
||||
title=?, category=?, image=?, role=?, biography=?, history=?,
|
||||
speech_pattern=?, catchphrase=?, residence=?, notes=?, color=?, last_update=?
|
||||
WHERE character_id=? AND user_id=?`;
|
||||
const params: SQLiteValue[] = [
|
||||
characterData.firstName, characterData.lastName, characterData.nickname,
|
||||
characterData.age, characterData.gender, characterData.species,
|
||||
characterData.nationality, characterData.status, characterData.title,
|
||||
characterData.category, characterData.image, characterData.role,
|
||||
characterData.biography, characterData.history, characterData.speechPattern,
|
||||
characterData.catchphrase, characterData.residence, characterData.notes,
|
||||
characterData.color, lastUpdate, id, userId
|
||||
];
|
||||
const query: string = seriesCharacterId !== null
|
||||
? 'UPDATE book_characters SET first_name=?, last_name=?, nickname=?, age=?, gender=?, species=?, nationality=?, status=?, title=?, category=?, image=?, role=?, biography=?, history=?, speech_pattern=?, catchphrase=?, residence=?, notes=?, color=?, series_character_id=?, last_update=? WHERE character_id=? AND user_id=?'
|
||||
: 'UPDATE book_characters SET first_name=?, last_name=?, nickname=?, age=?, gender=?, species=?, nationality=?, status=?, title=?, category=?, image=?, role=?, biography=?, history=?, speech_pattern=?, catchphrase=?, residence=?, notes=?, color=?, last_update=? WHERE character_id=? AND user_id=?';
|
||||
const params: SQLiteValue[] = seriesCharacterId !== null
|
||||
? [characterData.firstName, characterData.lastName, characterData.nickname, characterData.age, characterData.gender, characterData.species, characterData.nationality, characterData.status, characterData.title, characterData.category, characterData.image, characterData.role, characterData.biography, characterData.history, characterData.speechPattern, characterData.catchphrase, characterData.residence, characterData.notes, characterData.color, seriesCharacterId, lastUpdate, id, userId]
|
||||
: [characterData.firstName, characterData.lastName, characterData.nickname, characterData.age, characterData.gender, characterData.species, characterData.nationality, characterData.status, characterData.title, characterData.category, characterData.image, characterData.role, characterData.biography, characterData.history, characterData.speechPattern, characterData.catchphrase, characterData.residence, characterData.notes, characterData.color, lastUpdate, id, userId];
|
||||
const updateResult: RunResult = db.run(query, params);
|
||||
return updateResult.changes > 0;
|
||||
} catch (error: unknown) {
|
||||
@@ -357,7 +355,7 @@ export default class CharacterRepo {
|
||||
static fetchCompleteCharacters(userId: string, bookId: string, tags: string[], lang: 'fr' | 'en' = 'fr'): CompleteCharacterResult[] {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
let query: string = 'SELECT charac.character_id, first_name, last_name, category, title, role, biography, history, attribute_name, attribute_value FROM book_characters AS charac LEFT JOIN book_characters_attributes AS attr ON charac.character_id=attr.character_id WHERE charac.user_id=? AND charac.book_id=?';
|
||||
let query: string = 'SELECT charac.character_id, first_name, last_name, nickname, age, gender, species, nationality, status, category, title, role, biography, history, speech_pattern, catchphrase, residence, notes, color, attribute_name, attribute_value FROM book_characters AS charac LEFT JOIN book_characters_attributes AS attr ON charac.character_id=attr.character_id WHERE charac.user_id=? AND charac.book_id=?';
|
||||
let params: SQLiteValue[] = [userId, bookId];
|
||||
if (tags && tags.length > 0) {
|
||||
const placeholders: string = tags.map((): string => '?').join(',');
|
||||
@@ -393,7 +391,7 @@ export default class CharacterRepo {
|
||||
static updateCharacterAttribute(userId: string, characterAttributeId: string, attributeName: string, attributeValue: string, lastUpdate: number, lang: "fr" | "en"): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const query: string = 'UPDATE `book_characters_attributes` SET `attribute_name`=?,`attribute_value`=?, last_update=FROM_UNIXTIME(?) WHERE `attr_id`=UUID_TO_BIN(?) AND `user_id`=UUID_TO_BIN(?)';
|
||||
const query: string = 'UPDATE book_characters_attributes SET attribute_name=?, attribute_value=?, last_update=? WHERE attr_id=? AND user_id=?';
|
||||
const params: SQLiteValue[] = [attributeName, attributeValue, lastUpdate, characterAttributeId, userId];
|
||||
const updateResult: RunResult = db.run(query, params);
|
||||
return updateResult.changes > 0;
|
||||
|
||||
Reference in New Issue
Block a user