Update database schema and synchronization logic
- Add `useEffect` in `ScribeLeftBar` for handling book state changes. - Extend `BooksSyncContext` with new properties and stricter typings. - Refine `Repositories` to include `lastUpdate` handling for synchronization processes. - Add comprehensive `fetchComplete*` repository methods for retrieving entity-specific sync data. - Enhance offline logic for chapters, characters, locations, and world synchronization. - Improve error handling across IPC handlers and repositories.
This commit is contained in:
@@ -43,6 +43,8 @@ import fs from "fs";
|
||||
import Chapter, {ActChapter, ChapterContentData, ChapterProps} from "./Chapter.js";
|
||||
import UserRepo from "../repositories/user.repository.js";
|
||||
import ChapterRepo from "../repositories/chapter.repository.js";
|
||||
import CharacterRepo from "../repositories/character.repository.js";
|
||||
import LocationRepo from "../repositories/location.repository.js";
|
||||
|
||||
export interface BookProps{
|
||||
id:string;
|
||||
@@ -97,6 +99,26 @@ export interface SyncedBook {
|
||||
aiGuideLine: SyncedAIGuideLine | null;
|
||||
}
|
||||
|
||||
export interface BookSyncCompare {
|
||||
id: string;
|
||||
chapters: string[];
|
||||
chapterContents: string[];
|
||||
chapterInfos: string[];
|
||||
characters: string[];
|
||||
characterAttributes: string[];
|
||||
locations: string[];
|
||||
locationElements: string[];
|
||||
locationSubElements: string[];
|
||||
worlds: string[];
|
||||
worldElements: string[];
|
||||
incidents: string[];
|
||||
plotPoints: string[];
|
||||
issues: string[];
|
||||
actSummaries: string[];
|
||||
guideLine: boolean;
|
||||
aiGuideLine: boolean;
|
||||
}
|
||||
|
||||
export interface SyncedChapter {
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -617,7 +639,7 @@ export default class Book {
|
||||
if (actId === 1 || actId === 4 || actId === 5) {
|
||||
const actSummary: string = act.summary ? System.encryptDataWithUserKey(act.summary, userKey) : '';
|
||||
try {
|
||||
BookRepo.updateActSummary(userId, bookId, actId, actSummary,lang);
|
||||
BookRepo.updateActSummary(userId, bookId, actId, actSummary,System.timeStampInSeconds(),lang);
|
||||
} catch (e: unknown) {
|
||||
const actSummaryId: string = System.createUniqueId();
|
||||
BookRepo.insertActSummary(actSummaryId, userId, bookId, actId, actSummary,lang);
|
||||
@@ -632,7 +654,7 @@ export default class Book {
|
||||
const incidentName: string = incident.title;
|
||||
const incidentHashedName: string = System.hashElement(incidentName);
|
||||
const encryptedIncidentName: string = System.encryptDataWithUserKey(incidentName, userKey);
|
||||
BookRepo.updateIncident(userId, bookId, incidentId, encryptedIncidentName, incidentHashedName, incidentSummary, lang);
|
||||
BookRepo.updateIncident(userId, bookId, incidentId, encryptedIncidentName, incidentHashedName, incidentSummary, System.timeStampInSeconds(), lang);
|
||||
if (incident.chapters) {
|
||||
Chapter.updateChapterInfos(incident.chapters, userId, actId, bookId, incidentId, null, lang);
|
||||
}
|
||||
@@ -645,7 +667,7 @@ export default class Book {
|
||||
const plotPointName: string = plotPoint.title;
|
||||
const plotPointHashedName: string = System.hashElement(plotPointName);
|
||||
const encryptedPlotPointName: string = System.encryptDataWithUserKey(plotPointName, userKey);
|
||||
BookRepo.updatePlotPoint(userId, bookId, plotPointId, encryptedPlotPointName, plotPointHashedName, plotPointSummary, lang);
|
||||
BookRepo.updatePlotPoint(userId, bookId, plotPointId, encryptedPlotPointName, plotPointHashedName, plotPointSummary, System.timeStampInSeconds(), lang);
|
||||
if (plotPoint.chapters) {
|
||||
Chapter.updateChapterInfos(plotPoint.chapters, userId, actId, bookId, null, plotPointId, lang);
|
||||
}
|
||||
@@ -664,7 +686,7 @@ export default class Book {
|
||||
const chapterHashedTitle: string = System.hashElement(chapterTitle);
|
||||
const encryptedTitle: string = System.encryptDataWithUserKey(chapterTitle, userKey);
|
||||
const chapterOrder: number = chapter.chapterOrder;
|
||||
ChapterRepo.updateChapter(userId, chapterId, encryptedTitle, chapterHashedTitle, chapterOrder, lang);
|
||||
ChapterRepo.updateChapter(userId, chapterId, encryptedTitle, chapterHashedTitle, chapterOrder, System.timeStampInSeconds(), lang);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -849,7 +871,7 @@ export default class Book {
|
||||
}));
|
||||
});
|
||||
|
||||
BookRepo.updateWorld(userId, world.id, encryptName, System.hashElement(world.name), encryptHistory, encryptPolitics, encryptEconomy, encryptReligion, encryptLanguages, lang);
|
||||
BookRepo.updateWorld(userId, world.id, encryptName, System.hashElement(world.name), encryptHistory, encryptPolitics, encryptEconomy, encryptReligion, encryptLanguages, System.timeStampInSeconds(), lang);
|
||||
return BookRepo.updateWorldElements(userId, elements, lang);
|
||||
}
|
||||
|
||||
@@ -1466,4 +1488,450 @@ export default class Book {
|
||||
return BookRepo.insertSyncIssue(issue.issue_id, userId, issue.book_id, encryptedIssueName, issue.hashed_issue_name, issue.last_update, lang);
|
||||
});
|
||||
}
|
||||
|
||||
static async getCompleteSyncBook(userId: string, data: BookSyncCompare, lang: "fr" | "en"):Promise<CompleteBook> {
|
||||
const userKey: string = getUserEncryptionKey(userId);
|
||||
const bookData: EritBooksTable[] = [];
|
||||
const chaptersData: BookChaptersTable[] = [];
|
||||
const plotPointsData: BookPlotPointsTable[] = [];
|
||||
const incidentsData: BookIncidentsTable[] = [];
|
||||
const chapterContentsData: BookChapterContentTable[] = [];
|
||||
const chapterInfosData: BookChapterInfosTable[] = [];
|
||||
const charactersData: BookCharactersTable[] = [];
|
||||
const characterAttributesData: BookCharactersAttributesTable[] = [];
|
||||
const locationsData: BookLocationTable[] = [];
|
||||
const locationElementsData: LocationElementTable[] = [];
|
||||
const locationSubElementsData: LocationSubElementTable[] = [];
|
||||
const worldsData: BookWorldTable[] = [];
|
||||
const worldElementsData: BookWorldElementsTable[] = [];
|
||||
const actSummariesData: BookActSummariesTable[] = [];
|
||||
const guideLineData: BookGuideLineTable[] = [];
|
||||
const aiGuideLineData: BookAIGuideLineTable[] = [];
|
||||
const issuesData: BookIssuesTable[] = [];
|
||||
|
||||
const actSummaries: string[] = data.actSummaries;
|
||||
const chapters: string[] = data.chapters;
|
||||
const plotPoints: string[] = data.plotPoints;
|
||||
const incidents: string[] = data.incidents;
|
||||
const chapterContents: string[] = data.chapterContents;
|
||||
const chapterInfos: string[] = data.chapterInfos;
|
||||
const characters: string[] = data.characters;
|
||||
const characterAttributes: string[] = data.characterAttributes;
|
||||
const locations: string[] = data.locations;
|
||||
const locationElements: string[] = data.locationElements;
|
||||
const locationSubElements: string[] = data.locationSubElements;
|
||||
const worlds: string[] = data.worlds;
|
||||
const worldElements: string[] = data.worldElements;
|
||||
const issues: string[] = data.issues;
|
||||
|
||||
if (actSummaries && actSummaries.length > 0) {
|
||||
for (const id of actSummaries) {
|
||||
const actSummary: BookActSummariesTable[] = await BookRepo.fetchCompleteActSummaryById(id, lang);
|
||||
if (actSummary.length>0) {
|
||||
const actSummaryData: BookActSummariesTable = actSummary[0];
|
||||
actSummariesData.push({
|
||||
...actSummaryData,
|
||||
summary: actSummaryData.summary ? System.decryptDataWithUserKey(actSummaryData.summary, userKey) : null
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chapters && chapters.length > 0) {
|
||||
for (const id of chapters) {
|
||||
const chapter: BookChaptersTable[] = await BookRepo.fetchCompleteChapterById(id, lang);
|
||||
if (chapter.length>0) {
|
||||
const chapterData: BookChaptersTable = chapter[0];
|
||||
chaptersData.push({
|
||||
...chapterData,
|
||||
title: System.decryptDataWithUserKey(chapterData.title, userKey)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (plotPoints && plotPoints.length > 0) {
|
||||
for (const id of plotPoints) {
|
||||
const plotPoint: BookPlotPointsTable[] = await BookRepo.fetchCompletePlotPointById(id, lang);
|
||||
if (plotPoint.length>0) {
|
||||
const plotPointData: BookPlotPointsTable = plotPoint[0];
|
||||
plotPointsData.push({
|
||||
...plotPointData,
|
||||
title: System.decryptDataWithUserKey(plotPointData.title, userKey),
|
||||
summary: plotPointData.summary ? System.decryptDataWithUserKey(plotPointData.summary, userKey) : null
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (incidents && incidents.length > 0) {
|
||||
for (const id of incidents) {
|
||||
const incident: BookIncidentsTable[] = await BookRepo.fetchCompleteIncidentById(id, lang);
|
||||
if (incident.length>0) {
|
||||
const incidentData: BookIncidentsTable = incident[0];
|
||||
incidentsData.push({
|
||||
...incidentData,
|
||||
title: System.decryptDataWithUserKey(incidentData.title, userKey),
|
||||
summary: incidentData.summary ? System.decryptDataWithUserKey(incidentData.summary, userKey) : null
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chapterContents && chapterContents.length > 0) {
|
||||
for (const id of chapterContents) {
|
||||
const chapterContent: BookChapterContentTable[] = await BookRepo.fetchCompleteChapterContentById(id, lang);
|
||||
if (chapterContent.length>0) {
|
||||
const chapterContentData: BookChapterContentTable = chapterContent[0];
|
||||
chapterContentsData.push({
|
||||
...chapterContentData,
|
||||
content: chapterContentData.content ? JSON.parse(System.decryptDataWithUserKey(chapterContentData.content, userKey)) : null
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chapterInfos && chapterInfos.length > 0) {
|
||||
for (const id of chapterInfos) {
|
||||
const chapterInfo: BookChapterInfosTable[] = await BookRepo.fetchCompleteChapterInfoById(id, lang);
|
||||
if (chapterInfo.length>0) {
|
||||
const chapterInfoData: BookChapterInfosTable = chapterInfo[0];
|
||||
chapterInfosData.push({
|
||||
...chapterInfoData,
|
||||
summary: chapterInfoData.summary ? System.decryptDataWithUserKey(chapterInfoData.summary, userKey) : null,
|
||||
goal: chapterInfoData.goal ? System.decryptDataWithUserKey(chapterInfoData.goal, userKey) : null
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (characters && characters.length > 0) {
|
||||
for (const id of characters) {
|
||||
const character: BookCharactersTable[] = await BookRepo.fetchCompleteCharacterById(id, lang);
|
||||
if (character.length>0) {
|
||||
const characterData: BookCharactersTable = character[0];
|
||||
charactersData.push({
|
||||
...characterData,
|
||||
first_name: System.decryptDataWithUserKey(characterData.first_name, userKey),
|
||||
last_name: characterData.last_name ? System.decryptDataWithUserKey(characterData.last_name, userKey) : null,
|
||||
category: System.decryptDataWithUserKey(characterData.category, userKey),
|
||||
title: characterData.title ? System.decryptDataWithUserKey(characterData.title, userKey) : null,
|
||||
role: characterData.role ? System.decryptDataWithUserKey(characterData.role, userKey) : null,
|
||||
biography: characterData.biography ? System.decryptDataWithUserKey(characterData.biography, userKey) : null,
|
||||
history: characterData.history ? System.decryptDataWithUserKey(characterData.history, userKey) : null
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (characterAttributes && characterAttributes.length > 0) {
|
||||
for (const id of characterAttributes) {
|
||||
const characterAttribute: BookCharactersAttributesTable[] = await BookRepo.fetchCompleteCharacterAttributeById(id, lang);
|
||||
if (characterAttribute.length>0) {
|
||||
const characterAttributeData: BookCharactersAttributesTable = characterAttribute[0];
|
||||
characterAttributesData.push({
|
||||
...characterAttributeData,
|
||||
attribute_name: System.decryptDataWithUserKey(characterAttributeData.attribute_name, userKey),
|
||||
attribute_value: System.decryptDataWithUserKey(characterAttributeData.attribute_value, userKey)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (locations && locations.length > 0) {
|
||||
for (const id of locations) {
|
||||
const location: BookLocationTable[] = await BookRepo.fetchCompleteLocationById(id, lang);
|
||||
if (location.length>0) {
|
||||
const locationData: BookLocationTable = location[0];
|
||||
locationsData.push({
|
||||
...locationData,
|
||||
loc_name: System.decryptDataWithUserKey(locationData.loc_name, userKey)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (locationElements && locationElements.length > 0) {
|
||||
for (const id of locationElements) {
|
||||
const locationElement: LocationElementTable[] = await BookRepo.fetchCompleteLocationElementById(id, lang);
|
||||
if (locationElement.length>0) {
|
||||
const locationElementData: LocationElementTable = locationElement[0];
|
||||
locationElementsData.push({
|
||||
...locationElementData,
|
||||
element_name: System.decryptDataWithUserKey(locationElementData.element_name, userKey),
|
||||
element_description: locationElementData.element_description ? System.decryptDataWithUserKey(locationElementData.element_description, userKey) : null
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (locationSubElements && locationSubElements.length > 0) {
|
||||
for (const id of locationSubElements) {
|
||||
const locationSubElement: LocationSubElementTable[] = await BookRepo.fetchCompleteLocationSubElementById(id, lang);
|
||||
if (locationSubElement.length>0) {
|
||||
const locationSubElementData: LocationSubElementTable = locationSubElement[0];
|
||||
locationSubElementsData.push({
|
||||
...locationSubElementData,
|
||||
sub_elem_name: System.decryptDataWithUserKey(locationSubElementData.sub_elem_name, userKey),
|
||||
sub_elem_description: locationSubElementData.sub_elem_description ? System.decryptDataWithUserKey(locationSubElementData.sub_elem_description, userKey) : null
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (worlds && worlds.length > 0) {
|
||||
for (const id of worlds) {
|
||||
const world: BookWorldTable[] = await BookRepo.fetchCompleteWorldById(id, lang);
|
||||
if (world.length>0) {
|
||||
const worldData: BookWorldTable = world[0];
|
||||
worldsData.push({
|
||||
...worldData,
|
||||
name: System.decryptDataWithUserKey(worldData.name, userKey),
|
||||
history: worldData.history ? System.decryptDataWithUserKey(worldData.history, userKey) : null,
|
||||
politics: worldData.politics ? System.decryptDataWithUserKey(worldData.politics, userKey) : null,
|
||||
economy: worldData.economy ? System.decryptDataWithUserKey(worldData.economy, userKey) : null,
|
||||
religion: worldData.religion ? System.decryptDataWithUserKey(worldData.religion, userKey) : null,
|
||||
languages: worldData.languages ? System.decryptDataWithUserKey(worldData.languages, userKey) : null
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (worldElements && worldElements.length > 0) {
|
||||
for (const id of worldElements) {
|
||||
const worldElement: BookWorldElementsTable[] = await BookRepo.fetchCompleteWorldElementById(id, lang);
|
||||
if (worldElement.length>0) {
|
||||
const worldElementData: BookWorldElementsTable = worldElement[0];
|
||||
worldElementsData.push({
|
||||
...worldElementData,
|
||||
name: System.decryptDataWithUserKey(worldElementData.name, userKey),
|
||||
description: worldElementData.description ? System.decryptDataWithUserKey(worldElementData.description, userKey) : null
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (issues && issues.length > 0) {
|
||||
for (const id of issues) {
|
||||
const issue: BookIssuesTable[] = await BookRepo.fetchCompleteIssueById(id, lang);
|
||||
if (issue.length>0) {
|
||||
const issueData: BookIssuesTable = issue[0];
|
||||
issuesData.push({
|
||||
...issueData,
|
||||
name: System.decryptDataWithUserKey(issueData.name, userKey)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(data.id)
|
||||
const book: EritBooksTable[] = await BookRepo.fetchCompleteBookById(data.id, lang);
|
||||
if (book.length>0) {
|
||||
const bookDataItem: EritBooksTable = book[0];
|
||||
bookData.push({
|
||||
...bookDataItem,
|
||||
title: System.decryptDataWithUserKey(bookDataItem.title, userKey),
|
||||
sub_title: bookDataItem.sub_title ? System.decryptDataWithUserKey(bookDataItem.sub_title, userKey) : null,
|
||||
summary: bookDataItem.summary ? System.decryptDataWithUserKey(bookDataItem.summary, userKey) : null,
|
||||
cover_image: bookDataItem.cover_image ? System.decryptDataWithUserKey(bookDataItem.cover_image, userKey) : null
|
||||
});
|
||||
}
|
||||
return {
|
||||
eritBooks: bookData,
|
||||
chapters: chaptersData,
|
||||
plotPoints: plotPointsData,
|
||||
incidents: incidentsData,
|
||||
chapterContents: chapterContentsData,
|
||||
chapterInfos: chapterInfosData,
|
||||
characters: charactersData,
|
||||
characterAttributes: characterAttributesData,
|
||||
locations: locationsData,
|
||||
locationElements: locationElementsData,
|
||||
locationSubElements: locationSubElementsData,
|
||||
worlds: worldsData,
|
||||
worldElements: worldElementsData,
|
||||
actSummaries: actSummariesData,
|
||||
guideLine: guideLineData,
|
||||
aiGuideLine: aiGuideLineData,
|
||||
issues: issuesData
|
||||
};
|
||||
}
|
||||
|
||||
static async syncBookFromServerToClient(userId:string,completeBook: CompleteBook,lang:"fr"|"en"):Promise<boolean> {
|
||||
const userKey: string = getUserEncryptionKey(userId);
|
||||
const actSummaries: BookActSummariesTable[] = completeBook.actSummaries;
|
||||
const chapters: BookChaptersTable[] = completeBook.chapters;
|
||||
const plotPoints: BookPlotPointsTable[] = completeBook.plotPoints;
|
||||
const incidents: BookIncidentsTable[] = completeBook.incidents;
|
||||
const chapterContents: BookChapterContentTable[] = completeBook.chapterContents;
|
||||
const chapterInfos: BookChapterInfosTable[] = completeBook.chapterInfos;
|
||||
const characters: BookCharactersTable[] = completeBook.characters;
|
||||
const characterAttributes: BookCharactersAttributesTable[] = completeBook.characterAttributes;
|
||||
const locations: BookLocationTable[] = completeBook.locations;
|
||||
const locationElements: LocationElementTable[] = completeBook.locationElements;
|
||||
const locationSubElements: LocationSubElementTable[] = completeBook.locationSubElements;
|
||||
const worlds: BookWorldTable[] = completeBook.worlds;
|
||||
const worldElements: BookWorldElementsTable[] = completeBook.worldElements;
|
||||
const issues: BookIssuesTable[] = completeBook.issues;
|
||||
|
||||
const bookId: string = completeBook.eritBooks.length > 0 ? completeBook.eritBooks[0].book_id : '';
|
||||
|
||||
if (actSummaries && actSummaries.length > 0) {
|
||||
for (const actSummary of actSummaries) {
|
||||
const summary: string = System.encryptDataWithUserKey(actSummary.summary ? actSummary.summary : '', userKey)
|
||||
const updated: boolean = BookRepo.updateActSummary(userId, bookId, actSummary.act_index, summary, actSummary.last_update, lang);
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chapters && chapters.length > 0) {
|
||||
for (const chapter of chapters) {
|
||||
const title: string = System.encryptDataWithUserKey(chapter.title, userKey)
|
||||
const updated: boolean = ChapterRepo.updateChapter(userId, chapter.chapter_id, title, chapter.hashed_title, chapter.chapter_order, chapter.last_update, lang);
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (plotPoints && plotPoints.length > 0) {
|
||||
for (const plotPoint of plotPoints) {
|
||||
const title: string = System.encryptDataWithUserKey(plotPoint.title, userKey);
|
||||
const summary: string = System.encryptDataWithUserKey(plotPoint.summary ? plotPoint.summary : '', userKey);
|
||||
const updated: boolean = BookRepo.updatePlotPoint(userId, bookId, plotPoint.plot_point_id, title, plotPoint.hashed_title, summary, plotPoint.last_update,lang);
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (incidents && incidents.length > 0) {
|
||||
for (const incident of incidents) {
|
||||
const title: string = System.encryptDataWithUserKey(incident.title, userKey);
|
||||
const summary: string = System.encryptDataWithUserKey(incident.summary ? incident.summary : '', userKey);
|
||||
const updated: boolean = BookRepo.updateIncident(userId, bookId, incident.incident_id, title, incident.hashed_title, summary, incident.last_update, lang);
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chapterContents && chapterContents.length > 0) {
|
||||
for (const chapterContent of chapterContents) {
|
||||
const content: string = System.encryptDataWithUserKey(chapterContent.content ? JSON.stringify(chapterContent.content) : '', userKey);
|
||||
const updated: boolean = ChapterRepo.updateChapterContent(userId, chapterContent.chapter_id, chapterContent.version, content, chapterContent.words_count, chapterContent.last_update, lang);
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chapterInfos && chapterInfos.length > 0) {
|
||||
for (const chapterInfo of chapterInfos) {
|
||||
const summary: string = System.encryptDataWithUserKey(chapterInfo.summary ? chapterInfo.summary : '', userKey);
|
||||
const goal: string = System.encryptDataWithUserKey(chapterInfo.goal ? chapterInfo.goal : '', userKey);
|
||||
const updated: boolean = ChapterRepo.updateChapterInfos(userId, chapterInfo.chapter_id, chapterInfo.act_id, bookId,chapterInfo.incident_id, chapterInfo.plot_point_id, summary, goal, chapterInfo.last_update, lang);
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (characters && characters.length > 0) {
|
||||
for (const character of characters) {
|
||||
const firstName: string = System.encryptDataWithUserKey(character.first_name, userKey);
|
||||
const lastName: string = System.encryptDataWithUserKey(character.last_name ? character.last_name : '', userKey);
|
||||
const category: string = System.encryptDataWithUserKey(character.category, userKey);
|
||||
const title: string = System.encryptDataWithUserKey(character.title ? character.title : '', userKey);
|
||||
const role: string = System.encryptDataWithUserKey(character.role ? character.role : '', userKey);
|
||||
const biography: string = System.encryptDataWithUserKey(character.biography ? character.biography : '', userKey);
|
||||
const history: string = System.encryptDataWithUserKey(character.history ? character.history : '', userKey);
|
||||
const updated: boolean = CharacterRepo.updateCharacter(userId, character.character_id, firstName, lastName, title, category, character.image || '', role, biography, history, character.last_update, lang);
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (characterAttributes && characterAttributes.length > 0) {
|
||||
for (const characterAttribute of characterAttributes) {
|
||||
const attributeName: string = System.encryptDataWithUserKey(characterAttribute.attribute_name, userKey);
|
||||
const attributeValue: string = System.encryptDataWithUserKey(characterAttribute.attribute_value, userKey);
|
||||
const updated: boolean = CharacterRepo.updateCharacterAttribute(userId, characterAttribute.attr_id, attributeName, attributeValue, characterAttribute.last_update, lang);
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (locations && locations.length > 0) {
|
||||
for (const location of locations) {
|
||||
const locName: string = System.encryptDataWithUserKey(location.loc_name, userKey);
|
||||
const updated: boolean = LocationRepo.updateLocationSection(userId, location.loc_id, locName, location.loc_original_name, location.last_update, lang);
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (locationElements && locationElements.length > 0) {
|
||||
for (const locationElement of locationElements) {
|
||||
const elementName: string = System.encryptDataWithUserKey(locationElement.element_name, userKey);
|
||||
const elementDescription: string = System.encryptDataWithUserKey(locationElement.element_description ? locationElement.element_description : '', userKey);
|
||||
const updated: boolean = LocationRepo.updateLocationElement(userId, locationElement.element_id, elementName,locationElement.original_name, elementDescription, locationElement.last_update, lang);
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (locationSubElements && locationSubElements.length > 0) {
|
||||
for (const locationSubElement of locationSubElements) {
|
||||
const subElemName: string = System.encryptDataWithUserKey(locationSubElement.sub_elem_name, userKey);
|
||||
const subElemDescription: string = System.encryptDataWithUserKey(locationSubElement.sub_elem_description ? locationSubElement.sub_elem_description : '', userKey);
|
||||
const updated: boolean = LocationRepo.updateLocationSubElement(userId, locationSubElement.sub_element_id, subElemName, locationSubElement.original_name, subElemDescription, locationSubElement.last_update, lang);
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (worlds && worlds.length > 0) {
|
||||
for (const world of worlds) {
|
||||
const name: string = System.encryptDataWithUserKey(world.name, userKey);
|
||||
const history: string = System.encryptDataWithUserKey(world.history ? world.history : '', userKey);
|
||||
const politics: string = System.encryptDataWithUserKey(world.politics ? world.politics : '', userKey);
|
||||
const economy: string = System.encryptDataWithUserKey(world.economy ? world.economy : '', userKey);
|
||||
const religion: string = System.encryptDataWithUserKey(world.religion ? world.religion : '', userKey);
|
||||
const languages: string = System.encryptDataWithUserKey(world.languages ? world.languages : '', userKey);
|
||||
const updated: boolean = BookRepo.updateWorld(userId, world.world_id, name, world.hashed_name, history, politics, economy, religion, languages, world.last_update, lang);
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (worldElements && worldElements.length > 0) {
|
||||
for (const worldElement of worldElements) {
|
||||
const name: string = System.encryptDataWithUserKey(worldElement.name, userKey);
|
||||
const description: string = System.encryptDataWithUserKey(worldElement.description ? worldElement.description : '', userKey);
|
||||
const updated: boolean = BookRepo.updateWorldElement(userId, worldElement.element_id, name, description, worldElement.last_update, lang);
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (issues && issues.length > 0) {
|
||||
for (const issue of issues) {
|
||||
const name: string = System.encryptDataWithUserKey(issue.name, userKey);
|
||||
const updated: boolean = BookRepo.updateIssue(userId, bookId, issue.issue_id, name, issue.hashed_issue_name, issue.last_update, lang);
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user