Remove Story model handling verbal styles and linguistic properties
- Delete `Story` model implementation including `getVerbesStyle` method and related properties. - Cleanup unused interfaces and redundant logic from the codebase.
This commit is contained in:
@@ -97,7 +97,6 @@ export interface WorldElementValue {
|
||||
name: string;
|
||||
description: string;
|
||||
type: number;
|
||||
meta: string;
|
||||
}
|
||||
|
||||
export interface GuideLineAIQuery extends Record<string, SQLiteValue> {
|
||||
@@ -329,10 +328,10 @@ export default class BookRepo {
|
||||
}
|
||||
}
|
||||
|
||||
public static updateActSummary(userId: string, bookId: string, actId: number, summary: string, metaActs: string, lang: 'fr' | 'en'): boolean {
|
||||
public static updateActSummary(userId: string, bookId: string, actId: number, summary: string, lang: 'fr' | 'en'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: RunResult = db.run('UPDATE book_act_summaries SET summary=?, meta_acts=? WHERE user_id=? AND book_id=? AND act_sum_id=?', [summary, metaActs, userId, bookId, actId]);
|
||||
const result: RunResult = db.run('UPDATE book_act_summaries SET summary=? WHERE user_id=? AND book_id=? AND act_sum_id=?', [summary, userId, bookId, actId]);
|
||||
return result.changes > 0;
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
@@ -421,14 +420,14 @@ export default class BookRepo {
|
||||
}
|
||||
}
|
||||
|
||||
public static insertNewIssue(issueId: string, userId: string, bookId: string, encryptedName: string, hashedName: string, metaIssue: string, lang: 'fr' | 'en'): string {
|
||||
public static insertNewIssue(issueId: string, userId: string, bookId: string, encryptedName: string, hashedName: string, lang: 'fr' | 'en'): string {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result = db.get('SELECT issue_id FROM book_issues WHERE hashed_issue_name=? AND book_id=? AND author_id=?', [hashedName, bookId, userId]);
|
||||
if (result !== null) {
|
||||
throw new Error(lang === 'fr' ? `La problématique existe déjà.` : `This issue already exists.`);
|
||||
}
|
||||
const insertResult: RunResult = db.run('INSERT INTO book_issues (issue_id,author_id, book_id, name, hashed_issue_name, meta_issue) VALUES (?,?,?,?,?,?)', [issueId, userId, bookId, encryptedName, hashedName, metaIssue]);
|
||||
const insertResult: RunResult = db.run('INSERT INTO book_issues (issue_id,author_id, book_id, name, hashed_issue_name) VALUES (?,?,?,?,?)', [issueId, userId, bookId, encryptedName, hashedName]);
|
||||
if (insertResult.changes > 0) {
|
||||
return issueId;
|
||||
} else {
|
||||
@@ -461,10 +460,10 @@ export default class BookRepo {
|
||||
}
|
||||
}
|
||||
|
||||
public static updateIncident(userId: string, bookId: string, incidentId: string, encryptedIncidentName: string, incidentHashedName: string, incidentSummary: string, meta: string, lang: 'fr' | 'en'): boolean {
|
||||
public static updateIncident(userId: string, bookId: string, incidentId: string, encryptedIncidentName: string, incidentHashedName: string, incidentSummary: string, lang: 'fr' | 'en'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: RunResult = db.run('UPDATE book_incidents SET title=?, hashed_title=?, summary=?, meta_incident=? WHERE author_id=? AND book_id=? AND incident_id=?', [encryptedIncidentName, incidentHashedName, incidentSummary, meta, userId, bookId, incidentId]);
|
||||
const result: RunResult = db.run('UPDATE book_incidents SET title=?, hashed_title=?, summary=? WHERE author_id=? AND book_id=? AND incident_id=?', [encryptedIncidentName, incidentHashedName, incidentSummary, userId, bookId, incidentId]);
|
||||
return result.changes > 0;
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
@@ -477,10 +476,10 @@ export default class BookRepo {
|
||||
}
|
||||
}
|
||||
|
||||
public static updatePlotPoint(userId: string, bookId: string, plotPointId: string, encryptedPlotPointName: string, plotPointHashedName: string, plotPointSummary: string, meta: string, lang: 'fr' | 'en'): boolean {
|
||||
public static updatePlotPoint(userId: string, bookId: string, plotPointId: string, encryptedPlotPointName: string, plotPointHashedName: string, plotPointSummary: string, lang: 'fr' | 'en'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: RunResult = db.run('UPDATE book_plot_points SET title=?, hashed_title=?, summary=?, meta_plot=? WHERE author_id=? AND book_id=? AND plot_point_id=?', [encryptedPlotPointName, plotPointHashedName, plotPointSummary, meta, userId, bookId, plotPointId]);
|
||||
const result: RunResult = db.run('UPDATE book_plot_points SET title=?, hashed_title=?, summary=? WHERE author_id=? AND book_id=? AND plot_point_id=?', [encryptedPlotPointName, plotPointHashedName, plotPointSummary, userId, bookId, plotPointId]);
|
||||
return result.changes > 0;
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
@@ -508,10 +507,10 @@ export default class BookRepo {
|
||||
}
|
||||
}
|
||||
|
||||
public static insertNewWorld(worldId: string, userId: string, bookId: string, encryptedName: string, hashedName: string, meta: string, lang: 'fr' | 'en'): string {
|
||||
public static insertNewWorld(worldId: string, userId: string, bookId: string, encryptedName: string, hashedName: string, lang: 'fr' | 'en'): string {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: RunResult = db.run('INSERT INTO book_world (world_id,author_id, book_id, name, hashed_name, meta_world) VALUES (?,?,?,?,?,?)', [worldId, userId, bookId, encryptedName, hashedName, meta]);
|
||||
const result: RunResult = db.run('INSERT INTO book_world (world_id,author_id, book_id, name, hashed_name) VALUES (?,?,?,?,?)', [worldId, userId, bookId, encryptedName, hashedName]);
|
||||
if (result.changes > 0) {
|
||||
return worldId;
|
||||
} else {
|
||||
@@ -542,10 +541,10 @@ export default class BookRepo {
|
||||
}
|
||||
}
|
||||
|
||||
public static updateWorld(userId: string, worldId: string, encryptName: string, hashedName: string, encryptHistory: string, encryptPolitics: string, encryptEconomy: string, encryptReligion: string, encryptLanguages: string, meta: string, lang: 'fr' | 'en'): boolean {
|
||||
public static updateWorld(userId: string, worldId: string, encryptName: string, hashedName: string, encryptHistory: string, encryptPolitics: string, encryptEconomy: string, encryptReligion: string, encryptLanguages: string, lang: 'fr' | 'en'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: RunResult = db.run('UPDATE book_world SET name=?, hashed_name=?, history=?, politics=?, economy=?, religion=?, languages=?, meta_world=? WHERE author_id=? AND world_id=?', [encryptName, hashedName, encryptHistory, encryptPolitics, encryptEconomy, encryptReligion, encryptLanguages, meta, userId, worldId]);
|
||||
const result: RunResult = db.run('UPDATE book_world SET name=?, hashed_name=?, history=?, politics=?, economy=?, religion=?, languages=? WHERE author_id=? AND world_id=?', [encryptName, hashedName, encryptHistory, encryptPolitics, encryptEconomy, encryptReligion, encryptLanguages, userId, worldId]);
|
||||
return result.changes > 0;
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
@@ -562,7 +561,7 @@ export default class BookRepo {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
for (const element of elements) {
|
||||
const result: RunResult = db.run('UPDATE book_world_elements SET name=?, description=?, element_type=?, meta_element=? WHERE user_id=? AND element_id=?', [element.name, element.description, element.type, element.meta, userId, element.id]);
|
||||
const result: RunResult = db.run('UPDATE book_world_elements SET name=?, description=?, element_type=? WHERE user_id=? AND element_id=?', [element.name, element.description, element.type, userId, element.id]);
|
||||
if (result.changes <= 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -595,10 +594,10 @@ export default class BookRepo {
|
||||
}
|
||||
}
|
||||
|
||||
public static insertNewElement(userId: string, elementId: string, elementType: number, worldId: string, encryptedName: string, hashedName: string, meta: string, lang: 'fr' | 'en'): string {
|
||||
public static insertNewElement(userId: string, elementId: string, elementType: number, worldId: string, encryptedName: string, hashedName: string, lang: 'fr' | 'en'): string {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: RunResult = db.run('INSERT INTO book_world_elements (element_id,world_id,user_id, name, original_name, element_type, meta_element) VALUES (?,?,?,?,?,?,?)', [elementId, worldId, userId, encryptedName, hashedName, elementType, meta]);
|
||||
const result: RunResult = db.run('INSERT INTO book_world_elements (element_id,world_id,user_id, name, original_name, element_type) VALUES (?,?,?,?,?,?)', [elementId, worldId, userId, encryptedName, hashedName, elementType]);
|
||||
if (result.changes > 0) {
|
||||
return elementId;
|
||||
} else {
|
||||
@@ -647,14 +646,14 @@ export default class BookRepo {
|
||||
}
|
||||
}
|
||||
|
||||
static insertAIGuideLine(userId: string, bookId: string, narrativeType: number, dialogueType: number, encryptedPlotSummary: string, encryptedToneAtmosphere: string, verbTense: number, language: number, encryptedThemes: string, metaGuideLine: string, lang: 'fr' | 'en'): boolean {
|
||||
static insertAIGuideLine(userId: string, bookId: string, narrativeType: number, dialogueType: number, encryptedPlotSummary: string, encryptedToneAtmosphere: string, verbTense: number, language: number, encryptedThemes: string, lang: 'fr' | 'en'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
let result: RunResult = db.run('UPDATE book_ai_guide_line SET narrative_type=?, dialogue_type=?, global_resume=?, atmosphere=?, verbe_tense=?, langue=?, themes=?, meta=? WHERE user_id=? AND book_id=?', [narrativeType ? narrativeType : null, dialogueType ? dialogueType : null, encryptedPlotSummary, encryptedToneAtmosphere, verbTense ? verbTense : null, language ? language : null, encryptedThemes, metaGuideLine, userId, bookId]);
|
||||
let result: RunResult = db.run('UPDATE book_ai_guide_line SET narrative_type=?, dialogue_type=?, global_resume=?, atmosphere=?, verbe_tense=?, langue=?, themes=? WHERE user_id=? AND book_id=?', [narrativeType ? narrativeType : null, dialogueType ? dialogueType : null, encryptedPlotSummary, encryptedToneAtmosphere, verbTense ? verbTense : null, language ? language : null, encryptedThemes, userId, bookId]);
|
||||
if (result.changes > 0) {
|
||||
return true;
|
||||
} else {
|
||||
result = db.run('INSERT INTO book_ai_guide_line (user_id, book_id, global_resume, themes, verbe_tense, narrative_type, langue, dialogue_type, tone, atmosphere, current_resume, meta) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)', [userId, bookId, encryptedPlotSummary, encryptedThemes, verbTense ? verbTense : null, narrativeType ? narrativeType : null, language ? language : null, dialogueType ? dialogueType : null, encryptedToneAtmosphere, encryptedToneAtmosphere, encryptedPlotSummary, metaGuideLine]);
|
||||
result = db.run('INSERT INTO book_ai_guide_line (user_id, book_id, global_resume, themes, verbe_tense, narrative_type, langue, dialogue_type, tone, atmosphere, current_resume) VALUES (?,?,?,?,?,?,?,?,?,?,?)', [userId, bookId, encryptedPlotSummary, encryptedThemes, verbTense ? verbTense : null, narrativeType ? narrativeType : null, language ? language : null, dialogueType ? dialogueType : null, encryptedToneAtmosphere, encryptedToneAtmosphere, encryptedPlotSummary]);
|
||||
return result.changes > 0;
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
@@ -687,10 +686,10 @@ export default class BookRepo {
|
||||
}
|
||||
}
|
||||
|
||||
static insertActSummary(actSummaryId: string, userId: string, bookId: string, actId: number, actSummary: string, meta: string, lang: 'fr' | 'en'): string {
|
||||
static insertActSummary(actSummaryId: string, userId: string, bookId: string, actId: number, actSummary: string, lang: 'fr' | 'en'): string {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: RunResult = db.run('INSERT INTO book_act_summaries (act_sum_id, book_id, user_id, act_index, summary, meta_acts) VALUES (?,?,?,?,?,?)', [actSummaryId, bookId, userId, actId, actSummary, meta]);
|
||||
const result: RunResult = db.run('INSERT INTO book_act_summaries (act_sum_id, book_id, user_id, act_index, summary) VALUES (?,?,?,?,?)', [actSummaryId, bookId, userId, actId, actSummary]);
|
||||
if (result.changes > 0) {
|
||||
return actSummaryId;
|
||||
} else {
|
||||
|
||||
@@ -227,7 +227,7 @@ export default class ChapterRepo{
|
||||
public static updateChapter(userId: string, chapterId: string, encryptedTitle: string, hashTitle: string, chapterOrder: number, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: RunResult = db.run('UPDATE book_chapters SET title=?, hashed_title=?, chapter_order=?, meta_chapter=? WHERE author_id=? AND chapter_id=?', [encryptedTitle, hashTitle, chapterOrder, userId, chapterId]);
|
||||
const result: RunResult = db.run('UPDATE book_chapters SET title=?, hashed_title=?, chapter_order=? WHERE author_id=? AND chapter_id=?', [encryptedTitle, hashTitle, chapterOrder, userId, chapterId]);
|
||||
return result.changes > 0;
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
@@ -240,17 +240,16 @@ export default class ChapterRepo{
|
||||
}
|
||||
}
|
||||
|
||||
public static updateChapterInfos(userId: string, chapterId: string, actId: number, bookId: string, incidentId: string | null, plotId: string | null, summary: string, goal: string | null, meta: string, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
public static updateChapterInfos(userId: string, chapterId: string, actId: number, bookId: string, incidentId: string | null, plotId: string | null, summary: string, goal: string | null, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
let sql: string = `UPDATE book_chapter_infos
|
||||
SET summary=?,
|
||||
goal=?,
|
||||
meta_chapter_info=?
|
||||
goal=?
|
||||
WHERE chapter_id = ?
|
||||
AND act_id = ?
|
||||
AND book_id = ?`;
|
||||
const params: any[] = [summary, goal, meta, chapterId, actId, bookId];
|
||||
const params: any[] = [summary, goal, chapterId, actId, bookId];
|
||||
if (incidentId) {
|
||||
sql += ` AND incident_id=?`;
|
||||
params.push(incidentId);
|
||||
@@ -278,15 +277,15 @@ export default class ChapterRepo{
|
||||
}
|
||||
}
|
||||
|
||||
public static updateChapterContent(userId: string, chapterId: string, version: number, encryptContent: string, wordsCount: number, meta: string, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
public static updateChapterContent(userId: string, chapterId: string, version: number, encryptContent: string, wordsCount: number, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: RunResult = db.run('UPDATE book_chapter_content SET content=?, meta_chapter_content=?, words_count=? WHERE chapter_id=? AND author_id=? AND version=?', [encryptContent, meta, wordsCount, chapterId, userId, version]);
|
||||
const result: RunResult = db.run('UPDATE book_chapter_content SET content=?, words_count=? WHERE chapter_id=? AND author_id=? AND version=?', [encryptContent, wordsCount, chapterId, userId, version]);
|
||||
if (result.changes > 0) {
|
||||
return true;
|
||||
} else {
|
||||
const contentId:string = System.createUniqueId();
|
||||
const insertResult: RunResult = db.run('INSERT INTO book_chapter_content (content_id,chapter_id, author_id, version, content, words_count, meta_chapter_content) VALUES (?,?,?,?,?,?,?)', [contentId, chapterId, userId, version, encryptContent, wordsCount, meta]);
|
||||
const insertResult: RunResult = db.run('INSERT INTO book_chapter_content (content_id,chapter_id, author_id, version, content, words_count) VALUES (?,?,?,?,?,?)', [contentId, chapterId, userId, version, encryptContent, wordsCount]);
|
||||
return insertResult.changes > 0;
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
|
||||
@@ -54,11 +54,11 @@ export default class CharacterRepo {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static addNewCharacter(userId: string, characterId: string, encryptedName: string, encryptedLastName: string, encryptedTitle: string, encryptedCategory: string, encryptedImage: string, encryptedRole: string, encryptedBiography: string, encryptedHistory: string, bookId: string, meta: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
public static addNewCharacter(userId: string, characterId: string, encryptedName: string, encryptedLastName: string, encryptedTitle: string, encryptedCategory: string, encryptedImage: string, encryptedRole: string, encryptedBiography: string, encryptedHistory: string, bookId: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
let result: RunResult;
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
result = db.run('INSERT INTO `book_characters` (character_id, book_id, user_id, first_name, last_name, category, title, image, role, biography, history, char_meta) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)', [characterId, bookId, userId, encryptedName, encryptedLastName, encryptedCategory, encryptedTitle, encryptedImage, encryptedRole, encryptedBiography, encryptedHistory, meta]);
|
||||
result = db.run('INSERT INTO `book_characters` (character_id, book_id, user_id, first_name, last_name, category, title, image, role, biography, history) VALUES (?,?,?,?,?,?,?,?,?,?,?)', [characterId, bookId, userId, encryptedName, encryptedLastName, encryptedCategory, encryptedTitle, encryptedImage, encryptedRole, encryptedBiography, encryptedHistory]);
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
console.error(`DB Error: ${e.message}`);
|
||||
@@ -75,11 +75,11 @@ export default class CharacterRepo {
|
||||
}
|
||||
}
|
||||
|
||||
static insertAttribute(attributeId: string, characterId: string, userId: string, type: string, name: string, meta: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
static insertAttribute(attributeId: string, characterId: string, userId: string, type: string, name: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
let result: RunResult;
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
result = db.run('INSERT INTO `book_characters_attributes` (attr_id, character_id, user_id, attribute_name, attribute_value,attr_meta) VALUES (?,?,?,?,?,?)', [attributeId, characterId, userId, type, name, meta]);
|
||||
result = db.run('INSERT INTO `book_characters_attributes` (attr_id, character_id, user_id, attribute_name, attribute_value) VALUES (?,?,?,?,?)', [attributeId, characterId, userId, type, name]);
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
console.error(`DB Error: ${e.message}`);
|
||||
@@ -96,10 +96,10 @@ export default class CharacterRepo {
|
||||
}
|
||||
}
|
||||
|
||||
static updateCharacter(userId: string, id: number | null, encryptedName: string, encryptedLastName: string, encryptedTitle: string, encryptedCategory: string, encryptedImage: string, encryptedRole: string, encryptedBiography: string, encryptedHistory: string, meta: string, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
static updateCharacter(userId: string, id: number | null, encryptedName: string, encryptedLastName: string, encryptedTitle: string, encryptedCategory: string, encryptedImage: string, encryptedRole: string, encryptedBiography: string, encryptedHistory: string, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: RunResult = db.run('UPDATE `book_characters` SET `first_name`=?,`last_name`=?,`title`=?,`category`=?,`image`=?,`role`=?,`biography`=?,`history`=?, char_meta=? WHERE `character_id`=? AND `user_id`=?', [encryptedName, encryptedLastName, encryptedTitle, encryptedCategory, encryptedImage, encryptedRole, encryptedBiography, encryptedHistory, meta, id, userId]);
|
||||
const result: RunResult = db.run('UPDATE `book_characters` SET `first_name`=?,`last_name`=?,`title`=?,`category`=?,`image`=?,`role`=?,`biography`=?,`history`=? WHERE `character_id`=? AND `user_id`=?', [encryptedName, encryptedLastName, encryptedTitle, encryptedCategory, encryptedImage, encryptedRole, encryptedBiography, encryptedHistory, id, userId]);
|
||||
return result.changes > 0;
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
|
||||
@@ -54,11 +54,11 @@ export default class LocationRepo {
|
||||
return result;
|
||||
}
|
||||
|
||||
static insertLocation(userId: string, locationId: string, bookId: string, encryptedName: string, originalName: string, meta: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
static insertLocation(userId: string, locationId: string, bookId: string, encryptedName: string, originalName: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
let result: RunResult;
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
result = db.run('INSERT INTO book_location (loc_id, book_id, user_id, loc_name, loc_original_name, loc_meta) VALUES (?, ?, ?, ?, ?, ?)', [locationId, bookId, userId, encryptedName, originalName, meta]);
|
||||
result = db.run('INSERT INTO book_location (loc_id, book_id, user_id, loc_name, loc_original_name) VALUES (?, ?, ?, ?, ?)', [locationId, bookId, userId, encryptedName, originalName]);
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
console.error(`DB Error: ${e.message}`);
|
||||
@@ -75,11 +75,11 @@ export default class LocationRepo {
|
||||
}
|
||||
}
|
||||
|
||||
static insertLocationElement(userId: string, elementId: string, locationId: string, encryptedName: string, originalName: string, meta: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
static insertLocationElement(userId: string, elementId: string, locationId: string, encryptedName: string, originalName: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
let result: RunResult;
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
result = db.run('INSERT INTO location_element (element_id, location, user_id, element_name, original_name, element_description, element_meta) VALUES (?,?,?,?,?,?,?)', [elementId, locationId, userId, encryptedName, originalName, '', meta]);
|
||||
result = db.run('INSERT INTO location_element (element_id, location, user_id, element_name, original_name, element_description) VALUES (?,?,?,?,?,?)', [elementId, locationId, userId, encryptedName, originalName, '']);
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
console.error(`DB Error: ${e.message}`);
|
||||
@@ -96,11 +96,11 @@ export default class LocationRepo {
|
||||
}
|
||||
}
|
||||
|
||||
static insertLocationSubElement(userId: string, subElementId: string, elementId: string, encryptedName: string, originalName: string, meta: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
static insertLocationSubElement(userId: string, subElementId: string, elementId: string, encryptedName: string, originalName: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
let result: RunResult;
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
result = db.run('INSERT INTO location_sub_element (sub_element_id, element_id, user_id, sub_elem_name, original_name, sub_elem_description, sub_elem_meta) VALUES (?,?,?,?,?,?,?)', [subElementId, elementId, userId, encryptedName, originalName, '', meta]);
|
||||
result = db.run('INSERT INTO location_sub_element (sub_element_id, element_id, user_id, sub_elem_name, original_name, sub_elem_description) VALUES (?,?,?,?,?,?)', [subElementId, elementId, userId, encryptedName, originalName, '']);
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
console.error(`DB Error: ${e.message}`);
|
||||
@@ -117,10 +117,10 @@ export default class LocationRepo {
|
||||
}
|
||||
}
|
||||
|
||||
static updateLocationSubElement(userId: string, id: string, encryptedName: string, originalName: string, encryptDescription: string, meta: string, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
static updateLocationSubElement(userId: string, id: string, encryptedName: string, originalName: string, encryptDescription: string, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: RunResult = db.run('UPDATE location_sub_element SET sub_elem_name=?, original_name=?, sub_elem_description=?, sub_elem_meta=? WHERE sub_element_id=? AND user_id=?', [encryptedName, originalName, encryptDescription, meta, id, userId]);
|
||||
const result: RunResult = db.run('UPDATE location_sub_element SET sub_elem_name=?, original_name=?, sub_elem_description=? WHERE sub_element_id=? AND user_id=?', [encryptedName, originalName, encryptDescription, id, userId]);
|
||||
return result.changes > 0;
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
@@ -133,10 +133,10 @@ export default class LocationRepo {
|
||||
}
|
||||
}
|
||||
|
||||
static updateLocationElement(userId: string, id: string, encryptedName: string, originalName: string, encryptedDescription: string, meta: string, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
static updateLocationElement(userId: string, id: string, encryptedName: string, originalName: string, encryptedDescription: string, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: RunResult = db.run('UPDATE location_element SET element_name=?, original_name=?, element_description=?, element_meta=? WHERE element_id=? AND user_id=?', [encryptedName, originalName, encryptedDescription, meta, id, userId]);
|
||||
const result: RunResult = db.run('UPDATE location_element SET element_name=?, original_name=?, element_description=? WHERE element_id=? AND user_id=?', [encryptedName, originalName, encryptedDescription, id, userId]);
|
||||
return result.changes > 0;
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
@@ -149,10 +149,10 @@ export default class LocationRepo {
|
||||
}
|
||||
}
|
||||
|
||||
static updateLocationSection(userId: string, id: string, encryptedName: string, originalName: string, meta: string, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
static updateLocationSection(userId: string, id: string, encryptedName: string, originalName: string, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: RunResult = db.run('UPDATE book_location SET loc_name=?, loc_original_name=?, loc_meta=? WHERE loc_id=? AND user_id=?', [encryptedName, originalName, meta, id, userId]);
|
||||
const result: RunResult = db.run('UPDATE book_location SET loc_name=?, loc_original_name=? WHERE loc_id=? AND user_id=?', [encryptedName, originalName, id, userId]);
|
||||
return result.changes > 0;
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
|
||||
@@ -33,17 +33,6 @@ interface UserResponse {
|
||||
account_verified: boolean;
|
||||
}
|
||||
|
||||
export interface UserQueryResponse extends Record<string, SQLiteValue> {
|
||||
user_id: string;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
username: string;
|
||||
email: string;
|
||||
plateform: string;
|
||||
accountVerified: boolean;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface UserAccountQuery extends Record<string, SQLiteValue> {
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
@@ -53,77 +42,21 @@ export interface UserAccountQuery extends Record<string, SQLiteValue> {
|
||||
user_meta: string;
|
||||
}
|
||||
|
||||
export interface TOTPQuery extends Record<string, SQLiteValue> {
|
||||
user_id: number;
|
||||
email: string;
|
||||
totp_code: string;
|
||||
totp_meta: string;
|
||||
}
|
||||
|
||||
export interface PasswordResponse extends Record<string, SQLiteValue> {
|
||||
user_id: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface GuideTourResult extends Record<string, SQLiteValue> {
|
||||
step_tour: string;
|
||||
}
|
||||
|
||||
export interface UserSubscription extends Record<string, SQLiteValue> {
|
||||
user_id: string;
|
||||
sub_type: string;
|
||||
sub_tier: number;
|
||||
start_date: string;
|
||||
end_date: string;
|
||||
status: number;
|
||||
}
|
||||
|
||||
export interface UserAPIKeyResult extends Record<string, SQLiteValue> {
|
||||
brand: AIBrand,
|
||||
key: string | null,
|
||||
actif: number
|
||||
}
|
||||
|
||||
export interface UserAiUsageResult extends Record<string, SQLiteValue> {
|
||||
token_in: string;
|
||||
token_out: string;
|
||||
total_price: number;
|
||||
}
|
||||
|
||||
export interface BasicUserCredentials extends Record<string, SQLiteValue> {
|
||||
user_id: string,
|
||||
first_name: string,
|
||||
last_name: string,
|
||||
username: string,
|
||||
email: string,
|
||||
user_meta: string
|
||||
}
|
||||
|
||||
export default class UserRepo {
|
||||
public static updatePoints(points: number, userId: string, lang: 'fr' | 'en' = 'fr'): void {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
db.run('UPDATE `erit_users` SET `erite_points`=erite_points+? WHERE `user_id`=?', [points, userId]);
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
console.error(`DB Error: ${e.message}`);
|
||||
throw new Error(lang === 'fr' ? `Impossible de mettre à jour les points.` : `Unable to update points.`);
|
||||
} else {
|
||||
console.error("An unknown error occurred.");
|
||||
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static insertUser(uuId: string, firstName: string, lastName: string, username: string, originUsername: string, email: string, originEmail: string, password: string, meta: string, socialId: string | null, provider: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
public static insertUser(uuId: string, firstName: string, lastName: string, username: string, originUsername: string, email: string, originEmail: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
let result: RunResult;
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const query = `INSERT INTO erit_users (user_id, first_name, last_name, username, email, origin_email,
|
||||
origin_username, plateform, social_id, password, term_accepted,
|
||||
account_verified, user_meta)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, 1, ?)`;
|
||||
const values: (string | null | number)[] = [uuId, firstName, lastName, username, email, originEmail, originUsername, provider, socialId, password, meta];
|
||||
origin_username, term_accepted,
|
||||
account_verified)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, 0, 1)`;
|
||||
const values: (string | null | number)[] = [uuId, firstName, lastName, username, email, originEmail, originUsername];
|
||||
result = db.run(query, values);
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
@@ -145,7 +78,7 @@ export default class UserRepo {
|
||||
let result;
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
result = db.get('SELECT `first_name`, `last_name`, `username`, `email`, `plateform`, `term_accepted`, `account_verified`, user_meta, author_name, writing_lang, writing_level, erite_points AS rite_points, user_group, credits_balance FROM `erit_users` AS users LEFT JOIN user_preferences AS preference ON users.user_id=preference.user_id WHERE users.user_id=?', [userId]);
|
||||
result = db.get('SELECT `first_name`, `last_name`, `username`, `email`, `plateform`, `term_accepted`, `account_verified`, user_meta, author_name, erite_points AS rite_points, user_group, credits_balance FROM `erit_users` AS users LEFT JOIN user_preferences AS preference ON users.user_id=preference.user_id WHERE users.user_id=?', [userId]);
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
console.error(`DB Error: ${e.message}`);
|
||||
@@ -161,10 +94,10 @@ export default class UserRepo {
|
||||
return result as UserInfosQueryResponse;
|
||||
}
|
||||
|
||||
public static updateUserInfos(userId: string, firstName: string, lastName: string, username: string, originUsername: string, email: string, originEmail: string, userMeta: string, originalAuthorName: string, authorName: string, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
public static updateUserInfos(userId: string, firstName: string, lastName: string, username: string, originUsername: string, email: string, originEmail: string, originalAuthorName: string, authorName: string, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result: RunResult = db.run('UPDATE `erit_users` SET `first_name`=?, `last_name`=?, `username`=?, email=?,`origin_username`=?, user_meta=?, origin_author_name=? ,author_name=? WHERE user_id=? AND `origin_email`=?', [firstName, lastName, username, email, originUsername, userMeta, originalAuthorName, authorName, userId, originEmail]);
|
||||
const result: RunResult = db.run('UPDATE `erit_users` SET `first_name`=?, `last_name`=?, `username`=?, email=?,`origin_username`=?, origin_author_name=? ,author_name=? WHERE user_id=? AND `origin_email`=?', [firstName, lastName, username, email, originUsername, originalAuthorName, authorName, userId, originEmail]);
|
||||
return result.changes > 0;
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
@@ -196,20 +129,4 @@ export default class UserRepo {
|
||||
}
|
||||
return result as UserAccountQuery;
|
||||
}
|
||||
|
||||
static fetchGuideTour(userId: string, plateforme: string): GuideTourResult[] {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const result = db.all('SELECT `step_tour` FROM `logs_guide_tour` WHERE user_id=? AND plateforme=?', [userId, plateforme]) as GuideTourResult[];
|
||||
return result.length > 0 ? result : [];
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
console.error(e.message);
|
||||
return [];
|
||||
} else {
|
||||
console.error(`Une erreur inconnue est survenue lors de la récupération du guide tour.`);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user