Add synchronization support for guidelines and AI guidelines
- Implemented syncing for `GuideLine` and `AIGuideLine` entities with encryption and decryption workflows. - Refined `GuidelineRepo` methods to check existence and update/insert records for both guideline types. - Updated timestamp handling in `GuideLine` and `AIGuideLine` models for accurate tracking. - Corrected QuillSense localization keys for labels and descriptions. - Improved database queries and modularized logic for consistency.
This commit is contained in:
@@ -117,24 +117,30 @@ export default class GuidelineRepo {
|
||||
* @returns True if the operation was successful
|
||||
* @throws Error if the guideline cannot be updated or inserted
|
||||
*/
|
||||
static updateGuideLine(
|
||||
userId: string,
|
||||
bookId: string,
|
||||
encryptedTone: string,
|
||||
encryptedAtmosphere: string,
|
||||
encryptedWritingStyle: string,
|
||||
encryptedThemes: string,
|
||||
encryptedSymbolism: string,
|
||||
encryptedMotifs: string,
|
||||
encryptedNarrativeVoice: string,
|
||||
encryptedPacing: string,
|
||||
encryptedKeyMessages: string,
|
||||
encryptedIntendedAudience: string,
|
||||
lang: 'fr' | 'en'
|
||||
): boolean {
|
||||
/**
|
||||
* Updates or inserts a guideline for a specific book.
|
||||
* If the guideline exists, it updates it; otherwise, it inserts a new one.
|
||||
* @param userId - The user identifier
|
||||
* @param bookId - The book identifier
|
||||
* @param encryptedTone - The encrypted tone value
|
||||
* @param encryptedAtmosphere - The encrypted atmosphere value
|
||||
* @param encryptedWritingStyle - The encrypted writing style value
|
||||
* @param encryptedThemes - The encrypted themes value
|
||||
* @param encryptedSymbolism - The encrypted symbolism value
|
||||
* @param encryptedMotifs - The encrypted motifs value
|
||||
* @param encryptedNarrativeVoice - The encrypted narrative voice value
|
||||
* @param encryptedPacing - The encrypted pacing value
|
||||
* @param encryptedKeyMessages - The encrypted key messages value
|
||||
* @param encryptedIntendedAudience - The encrypted intended audience value
|
||||
* @param lastUpdate - The timestamp of the last update
|
||||
* @param lang - The language for error messages ('fr' or 'en')
|
||||
* @returns True if the operation was successful
|
||||
* @throws Error if the guideline cannot be updated or inserted
|
||||
*/
|
||||
static updateGuideLine(userId: string, bookId: string, encryptedTone: string | null, encryptedAtmosphere: string | null, encryptedWritingStyle: string | null, encryptedThemes: string | null, encryptedSymbolism: string | null, encryptedMotifs: string | null, encryptedNarrativeVoice: string | null, encryptedPacing: string | null, encryptedKeyMessages: string | null, encryptedIntendedAudience: string | null, lastUpdate: number, lang: 'fr' | 'en'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const updateQuery: string = 'UPDATE book_guide_line SET tone=?, atmosphere=?, writing_style=?, themes=?, symbolism=?, motifs=?, narrative_voice=?, pacing=?, key_messages=?, last_update=? WHERE user_id=? AND book_id=?';
|
||||
const updateQuery: string = 'UPDATE book_guide_line SET tone=?, atmosphere=?, writing_style=?, themes=?, symbolism=?, motifs=?, narrative_voice=?, pacing=?, intended_audience=?, key_messages=?, last_update=? WHERE user_id=? AND book_id=?';
|
||||
const updateParams: SQLiteValue[] = [
|
||||
encryptedTone,
|
||||
encryptedAtmosphere,
|
||||
@@ -144,8 +150,9 @@ export default class GuidelineRepo {
|
||||
encryptedMotifs,
|
||||
encryptedNarrativeVoice,
|
||||
encryptedPacing,
|
||||
encryptedIntendedAudience,
|
||||
encryptedKeyMessages,
|
||||
System.timeStampInSeconds(),
|
||||
lastUpdate,
|
||||
userId,
|
||||
bookId
|
||||
];
|
||||
@@ -168,7 +175,7 @@ export default class GuidelineRepo {
|
||||
encryptedPacing,
|
||||
encryptedIntendedAudience,
|
||||
encryptedKeyMessages,
|
||||
System.timeStampInSeconds()
|
||||
lastUpdate
|
||||
];
|
||||
const insertResult: RunResult = db.run(insertQuery, insertParams);
|
||||
return insertResult.changes > 0;
|
||||
@@ -196,34 +203,24 @@ export default class GuidelineRepo {
|
||||
* @param verbTense - The verb tense identifier
|
||||
* @param language - The language identifier
|
||||
* @param encryptedThemes - The encrypted themes value
|
||||
* @param lastUpdate - The timestamp of the last update
|
||||
* @param lang - The language for error messages ('fr' or 'en')
|
||||
* @returns True if the operation was successful
|
||||
* @throws Error if the AI guideline cannot be inserted or updated
|
||||
*/
|
||||
static insertAIGuideLine(
|
||||
userId: string,
|
||||
bookId: string,
|
||||
narrativeType: number,
|
||||
dialogueType: number,
|
||||
encryptedPlotSummary: string,
|
||||
encryptedToneAtmosphere: string,
|
||||
verbTense: number,
|
||||
language: number,
|
||||
encryptedThemes: string,
|
||||
lang: 'fr' | 'en'
|
||||
): boolean {
|
||||
static insertAIGuideLine(userId: string, bookId: string, narrativeType: number | null, dialogueType: number | null, encryptedPlotSummary: string | null, encryptedToneAtmosphere: string | null, verbTense: number | null, language: number | null, encryptedThemes: string | null, lastUpdate: number, lang: 'fr' | 'en'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const updateQuery: string = 'UPDATE book_ai_guide_line SET narrative_type=?, dialogue_type=?, global_resume=?, atmosphere=?, verbe_tense=?, langue=?, themes=?, last_update=? WHERE user_id=? AND book_id=?';
|
||||
const updateParams: SQLiteValue[] = [
|
||||
narrativeType ? narrativeType : null,
|
||||
dialogueType ? dialogueType : null,
|
||||
narrativeType,
|
||||
dialogueType,
|
||||
encryptedPlotSummary,
|
||||
encryptedToneAtmosphere,
|
||||
verbTense ? verbTense : null,
|
||||
language ? language : null,
|
||||
verbTense,
|
||||
language,
|
||||
encryptedThemes,
|
||||
System.timeStampInSeconds(),
|
||||
lastUpdate,
|
||||
userId,
|
||||
bookId
|
||||
];
|
||||
@@ -238,14 +235,14 @@ export default class GuidelineRepo {
|
||||
bookId,
|
||||
encryptedPlotSummary,
|
||||
encryptedThemes,
|
||||
verbTense ? verbTense : null,
|
||||
narrativeType ? narrativeType : null,
|
||||
language ? language : null,
|
||||
dialogueType ? dialogueType : null,
|
||||
verbTense,
|
||||
narrativeType,
|
||||
language,
|
||||
dialogueType,
|
||||
encryptedToneAtmosphere,
|
||||
encryptedToneAtmosphere,
|
||||
encryptedPlotSummary,
|
||||
System.timeStampInSeconds()
|
||||
lastUpdate
|
||||
];
|
||||
const insertResult: RunResult = db.run(insertQuery, insertParams);
|
||||
return insertResult.changes > 0;
|
||||
@@ -391,6 +388,54 @@ export default class GuidelineRepo {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a guideline exists for a specific book.
|
||||
* @param userId - The unique identifier of the user.
|
||||
* @param bookId - The unique identifier of the book.
|
||||
* @param lang - The language for error messages ('fr' or 'en').
|
||||
* @returns True if the guideline exists, false otherwise.
|
||||
*/
|
||||
static guideLineExist(userId: string, bookId: string, lang: 'fr' | 'en'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const query: string = 'SELECT 1 FROM book_guide_line WHERE user_id=? AND book_id=?';
|
||||
const params: SQLiteValue[] = [userId, bookId];
|
||||
const result: Record<string, SQLiteValue> | undefined = db.get(query, params) as Record<string, SQLiteValue> | undefined;
|
||||
return result !== undefined;
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
console.error(`DB Error: ${error.message}`);
|
||||
throw new Error(lang === 'fr' ? `Impossible de vérifier l'existence de la ligne directrice.` : `Unable to check guideline existence.`);
|
||||
} else {
|
||||
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an AI guideline exists for a specific book.
|
||||
* @param userId - The unique identifier of the user.
|
||||
* @param bookId - The unique identifier of the book.
|
||||
* @param lang - The language for error messages ('fr' or 'en').
|
||||
* @returns True if the AI guideline exists, false otherwise.
|
||||
*/
|
||||
static aiGuideLineExist(userId: string, bookId: string, lang: 'fr' | 'en'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const query: string = 'SELECT 1 FROM book_ai_guide_line WHERE user_id=? AND book_id=?';
|
||||
const params: SQLiteValue[] = [userId, bookId];
|
||||
const result: Record<string, SQLiteValue> | undefined = db.get(query, params) as Record<string, SQLiteValue> | undefined;
|
||||
return result !== undefined;
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
console.error(`DB Error: ${error.message}`);
|
||||
throw new Error(lang === 'fr' ? `Impossible de vérifier l'existence de la ligne directrice IA.` : `Unable to check AI guideline existence.`);
|
||||
} else {
|
||||
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a synced AI guideline for a specific book.
|
||||
* @param userId - The user identifier
|
||||
|
||||
Reference in New Issue
Block a user