Add error handling, enhance syncing, and refactor deletion logic
- Introduce new error messages for syncing and book deletion in `en.json`. - Update `DeleteBook` to support local-only deletion and synced book management. - Refine offline/online behavior with `deleteLocalToo` checkbox and update related state handling. - Extend repository and IPC methods to handle optional IDs for updates. - Add `SyncQueueContext` for queueing offline changes and improving synchronization workflows. - Enhance refined text generation logic in `DraftCompanion` and `GhostWriter` components. - Replace PUT with PATCH for world updates to align with API expectations. - Streamline `AlertBox` by integrating dynamic translation keys for deletion prompts.
This commit is contained in:
@@ -487,11 +487,11 @@ export default class Book {
|
||||
return BookRepo.updateGuideLine(userId, bookId, encryptedTone, encryptedAtmosphere, encryptedWritingStyle, encryptedThemes, encryptedSymbolism, encryptedMotifs, encryptedNarrativeVoice, encryptedPacing, encryptedKeyMessages, encryptedIntendedAudience, lang);
|
||||
}
|
||||
|
||||
public static addNewIncident(userId: string, bookId: string, name: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
public static addNewIncident(userId: string, bookId: string, name: string, lang: 'fr' | 'en' = 'fr', existingIncidentId?: string): string {
|
||||
const userKey: string = getUserEncryptionKey(userId);
|
||||
const encryptedName:string = System.encryptDataWithUserKey(name,userKey);
|
||||
const hashedName:string = System.hashElement(name);
|
||||
const incidentId: string = System.createUniqueId();
|
||||
const incidentId: string = existingIncidentId || System.createUniqueId();
|
||||
return BookRepo.insertNewIncident(incidentId, userId, bookId, encryptedName, hashedName, lang);
|
||||
}
|
||||
public static async getPlotPoints(userId:string, bookId: string,actChapters:ActChapter[], lang: 'fr' | 'en' = 'fr'):Promise<PlotPoint[]>{
|
||||
@@ -608,11 +608,11 @@ export default class Book {
|
||||
return BookRepo.updateBookBasicInformation(userId, encryptedTitle, hashedTitle, encryptedSubTitle, hashedSubTitle, encryptedSummary, publicationDate, wordCount, bookId, lang);
|
||||
}
|
||||
|
||||
static addNewPlotPoint(userId: string, bookId: string, incidentId: string, name: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
static addNewPlotPoint(userId: string, bookId: string, incidentId: string, name: string, lang: 'fr' | 'en' = 'fr', existingPlotPointId?: string): string {
|
||||
const userKey:string = getUserEncryptionKey(userId);
|
||||
const encryptedName:string = System.encryptDataWithUserKey(name, userKey);
|
||||
const hashedName:string = System.hashElement(name);
|
||||
const plotPointId: string = System.createUniqueId();
|
||||
const plotPointId: string = existingPlotPointId || System.createUniqueId();
|
||||
return BookRepo.insertNewPlotPoint(plotPointId, userId, bookId, encryptedName, hashedName, incidentId, lang);
|
||||
}
|
||||
|
||||
@@ -620,11 +620,11 @@ export default class Book {
|
||||
return BookRepo.deletePlotPoint(userId, plotId, lang);
|
||||
}
|
||||
|
||||
public static addNewIssue(userId: string, bookId: string, name: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
public static addNewIssue(userId: string, bookId: string, name: string, lang: 'fr' | 'en' = 'fr', existingIssueId?: string): string {
|
||||
const userKey:string = getUserEncryptionKey(userId);
|
||||
const encryptedName:string = System.encryptDataWithUserKey(name,userKey);
|
||||
const hashedName:string = System.hashElement(name);
|
||||
const issueId: string = System.createUniqueId();
|
||||
const issueId: string = existingIssueId || System.createUniqueId();
|
||||
return BookRepo.insertNewIssue(issueId, userId, bookId, encryptedName, hashedName,lang);
|
||||
}
|
||||
|
||||
@@ -691,14 +691,14 @@ export default class Book {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static addNewWorld(userId: string, bookId: string, worldName: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
public static addNewWorld(userId: string, bookId: string, worldName: string, lang: 'fr' | 'en' = 'fr', existingWorldId?: string): string {
|
||||
const userKey: string = getUserEncryptionKey(userId);
|
||||
const hashedName: string = System.hashElement(worldName);
|
||||
if (BookRepo.checkWorldExist(userId, bookId, hashedName, lang)) {
|
||||
if (!existingWorldId && BookRepo.checkWorldExist(userId, bookId, hashedName, lang)) {
|
||||
throw new Error(lang === "fr" ? `Tu as déjà un monde ${worldName}.` : `You already have a world named ${worldName}.`);
|
||||
}
|
||||
const encryptedName: string = System.encryptDataWithUserKey(worldName, userKey);
|
||||
const worldId: string = System.createUniqueId();
|
||||
const worldId: string = existingWorldId || System.createUniqueId();
|
||||
return BookRepo.insertNewWorld(worldId, userId, bookId, encryptedName, hashedName, lang);
|
||||
}
|
||||
|
||||
@@ -875,15 +875,15 @@ export default class Book {
|
||||
return BookRepo.updateWorldElements(userId, elements, lang);
|
||||
}
|
||||
|
||||
public static addNewElementToWorld(userId: string, worldId: string, elementName: string, elementType: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
public static addNewElementToWorld(userId: string, worldId: string, elementName: string, elementType: string, lang: 'fr' | 'en' = 'fr', existingElementId?: string): string {
|
||||
const userKey: string = getUserEncryptionKey(userId);
|
||||
const hashedName: string = System.hashElement(elementName);
|
||||
if (BookRepo.checkElementExist(worldId, hashedName, lang)) {
|
||||
if (!existingElementId && BookRepo.checkElementExist(worldId, hashedName, lang)) {
|
||||
throw new Error(lang === "fr" ? `Vous avez déjà un élément avec ce nom ${elementName}.` : `You already have an element named ${elementName}.`);
|
||||
}
|
||||
const elementTypeId: number = Book.getElementTypes(elementType);
|
||||
const encryptedName: string = System.encryptDataWithUserKey(elementName, userKey);
|
||||
const elementId: string = System.createUniqueId();
|
||||
const elementId: string = existingElementId || System.createUniqueId();
|
||||
return BookRepo.insertNewElement(userId, elementId, elementTypeId, worldId, encryptedName, hashedName, lang);
|
||||
}
|
||||
public static getElementTypes(elementType:string):number{
|
||||
|
||||
@@ -172,15 +172,15 @@ export default class Chapter {
|
||||
};
|
||||
}
|
||||
|
||||
public static addChapter(userId: string, bookId: string, title: string, wordsCount: number, chapterOrder: number, lang: 'fr' | 'en' = 'fr'): string {
|
||||
public static addChapter(userId: string, bookId: string, title: string, wordsCount: number, chapterOrder: number, lang: 'fr' | 'en' = 'fr', existingChapterId?: string): string {
|
||||
const hashedTitle: string = System.hashElement(title);
|
||||
const userKey: string = getUserEncryptionKey(userId);
|
||||
const encryptedTitle: string = System.encryptDataWithUserKey(title, userKey);
|
||||
|
||||
if (ChapterRepo.checkNameDuplication(userId, bookId, hashedTitle, lang)) {
|
||||
if (!existingChapterId && ChapterRepo.checkNameDuplication(userId, bookId, hashedTitle, lang)) {
|
||||
throw new Error(lang === 'fr' ? `Ce nom de chapitre existe déjà.` : `This chapter name already exists.`);
|
||||
}
|
||||
const chapterId: string = System.createUniqueId();
|
||||
const chapterId: string = existingChapterId || System.createUniqueId();
|
||||
return ChapterRepo.insertChapter(chapterId, userId, bookId, encryptedTitle, hashedTitle, wordsCount, chapterOrder, lang);
|
||||
}
|
||||
|
||||
@@ -188,8 +188,8 @@ export default class Chapter {
|
||||
return ChapterRepo.deleteChapter(userId, chapterId, lang);
|
||||
}
|
||||
|
||||
public static addChapterInformation(userId: string, chapterId: string, actId: number, bookId: string, plotId: string | null, incidentId: string | null, lang: 'fr' | 'en' = 'fr'): string {
|
||||
const chapterInfoId: string = System.createUniqueId();
|
||||
public static addChapterInformation(userId: string, chapterId: string, actId: number, bookId: string, plotId: string | null, incidentId: string | null, lang: 'fr' | 'en' = 'fr', existingChapterInfoId?: string): string {
|
||||
const chapterInfoId: string = existingChapterInfoId || System.createUniqueId();
|
||||
return ChapterRepo.insertChapterInformation(chapterInfoId, userId, chapterId, actId, bookId, plotId, incidentId, lang);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,9 +88,9 @@ export default class Character {
|
||||
return characterList;
|
||||
}
|
||||
|
||||
public static addNewCharacter(userId: string, character: CharacterPropsPost, bookId: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
public static addNewCharacter(userId: string, character: CharacterPropsPost, bookId: string, lang: 'fr' | 'en' = 'fr', existingCharacterId?: string): string {
|
||||
const userKey: string = getUserEncryptionKey(userId);
|
||||
const characterId: string = System.createUniqueId();
|
||||
const characterId: string = existingCharacterId || System.createUniqueId();
|
||||
const encryptedName: string = System.encryptDataWithUserKey(character.name, userKey);
|
||||
const encryptedLastName: string = System.encryptDataWithUserKey(character.lastName, userKey);
|
||||
const encryptedTitle: string = System.encryptDataWithUserKey(character.title, userKey);
|
||||
@@ -132,9 +132,9 @@ export default class Character {
|
||||
return CharacterRepo.updateCharacter(userId, character.id, encryptedName, encryptedLastName, encryptedTitle, encryptedCategory, encryptedImage, encryptedRole, encryptedBiography, encryptedHistory, System.timeStampInSeconds(), lang);
|
||||
}
|
||||
|
||||
static addNewAttribute(characterId: string, userId: string, type: string, name: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
static addNewAttribute(characterId: string, userId: string, type: string, name: string, lang: 'fr' | 'en' = 'fr', existingAttributeId?: string): string {
|
||||
const userKey: string = getUserEncryptionKey(userId);
|
||||
const attributeId: string = System.createUniqueId();
|
||||
const attributeId: string = existingAttributeId || System.createUniqueId();
|
||||
const encryptedType: string = System.encryptDataWithUserKey(type, userKey);
|
||||
const encryptedName: string = System.encryptDataWithUserKey(name, userKey);
|
||||
return CharacterRepo.insertAttribute(attributeId, characterId, userId, encryptedType, encryptedName, lang);
|
||||
|
||||
@@ -88,27 +88,27 @@ export default class Location {
|
||||
return locationArray;
|
||||
}
|
||||
|
||||
static addLocationSection(userId: string, locationName: string, bookId: string, lang: 'fr' | 'en' = 'fr'): string {
|
||||
static addLocationSection(userId: string, locationName: string, bookId: string, lang: 'fr' | 'en' = 'fr', existingLocationId?: string): string {
|
||||
const userKey: string = getUserEncryptionKey(userId);
|
||||
const originalName: string = System.hashElement(locationName);
|
||||
const encryptedName: string = System.encryptDataWithUserKey(locationName, userKey);
|
||||
const locationId: string = System.createUniqueId();
|
||||
const locationId: string = existingLocationId || System.createUniqueId();
|
||||
return LocationRepo.insertLocation(userId, locationId, bookId, encryptedName, originalName, lang);
|
||||
}
|
||||
|
||||
static addLocationElement(userId: string, locationId: string, elementName: string, lang: 'fr' | 'en' = 'fr') {
|
||||
static addLocationElement(userId: string, locationId: string, elementName: string, lang: 'fr' | 'en' = 'fr', existingElementId?: string) {
|
||||
const userKey: string = getUserEncryptionKey(userId);
|
||||
const originalName: string = System.hashElement(elementName);
|
||||
const encryptedName: string = System.encryptDataWithUserKey(elementName, userKey);
|
||||
const elementId: string = System.createUniqueId();
|
||||
const elementId: string = existingElementId || System.createUniqueId();
|
||||
return LocationRepo.insertLocationElement(userId, elementId, locationId, encryptedName, originalName, lang)
|
||||
}
|
||||
|
||||
static addLocationSubElement(userId: string, elementId: string, subElementName: string, lang: 'fr' | 'en' = 'fr') {
|
||||
static addLocationSubElement(userId: string, elementId: string, subElementName: string, lang: 'fr' | 'en' = 'fr', existingSubElementId?: string) {
|
||||
const userKey: string = getUserEncryptionKey(userId);
|
||||
const originalName: string = System.hashElement(subElementName);
|
||||
const encryptedName: string = System.encryptDataWithUserKey(subElementName, userKey);
|
||||
const subElementId: string = System.createUniqueId();
|
||||
const subElementId: string = existingSubElementId || System.createUniqueId();
|
||||
return LocationRepo.insertLocationSubElement(userId, subElementId, elementId, encryptedName, originalName, lang)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user