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:
@@ -24,6 +24,7 @@ export interface LocationProps {
|
||||
id: string;
|
||||
name: string;
|
||||
elements: Element[];
|
||||
seriesLocationId?: string | null;
|
||||
}
|
||||
|
||||
export interface LocationListResponse {
|
||||
@@ -79,7 +80,8 @@ export default class Location {
|
||||
location = {
|
||||
id: record.loc_id,
|
||||
name: decryptedName,
|
||||
elements: []
|
||||
elements: [],
|
||||
seriesLocationId: record.series_location_id || null,
|
||||
};
|
||||
locationArray.push(location);
|
||||
}
|
||||
@@ -127,12 +129,12 @@ export default class Location {
|
||||
* @param existingLocationId - Optional existing location ID to use instead of generating a new one.
|
||||
* @returns The ID of the created location.
|
||||
*/
|
||||
static addLocationSection(userId: string, locationName: string, bookId: string, lang: 'fr' | 'en' = 'fr', existingLocationId?: string): string {
|
||||
static addLocationSection(userId: string, locationName: string, bookId: string, lang: 'fr' | 'en' = 'fr', existingLocationId?: string, seriesLocationId: string | null = null): string {
|
||||
const userKey: string = getUserEncryptionKey(userId);
|
||||
const hashedName: string = System.hashElement(locationName);
|
||||
const encryptedName: string = System.encryptDataWithUserKey(locationName, userKey);
|
||||
const locationId: string = existingLocationId || System.createUniqueId();
|
||||
return LocationRepo.insertLocation(userId, locationId, bookId, encryptedName, hashedName, lang);
|
||||
return LocationRepo.insertLocation(userId, locationId, bookId, encryptedName, hashedName, lang, seriesLocationId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,6 +204,28 @@ export default class Location {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a location section with optional name change and series link.
|
||||
* @param userId - The unique identifier of the user
|
||||
* @param sectionId - The unique identifier of the section
|
||||
* @param sectionName - The new name (optional)
|
||||
* @param seriesLocationId - The series location ID to link (optional, null to unlink)
|
||||
* @param lang - The language for error messages ('fr' or 'en'). Defaults to 'fr'.
|
||||
* @returns True if the update was successful
|
||||
*/
|
||||
static updateSectionWithSeriesLink(userId: string, sectionId: string, sectionName?: string, seriesLocationId?: string | null, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
let encryptedName: string | null = null;
|
||||
let originalNameHash: string | null = null;
|
||||
|
||||
if (sectionName) {
|
||||
const userKey: string = getUserEncryptionKey(userId);
|
||||
encryptedName = System.encryptDataWithUserKey(sectionName, userKey);
|
||||
originalNameHash = System.hashElement(sectionName);
|
||||
}
|
||||
|
||||
return LocationRepo.updateSectionWithSeriesLink(userId, sectionId, encryptedName, originalNameHash, seriesLocationId ?? null, lang);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a location section and all its associated elements and sub-elements.
|
||||
* @param userId - The user's unique identifier.
|
||||
|
||||
Reference in New Issue
Block a user