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:
natreex
2025-11-17 21:32:42 -05:00
parent baa45ac106
commit 3bc30d42ad
12 changed files with 259 additions and 1761 deletions

View File

@@ -1,10 +1,10 @@
import User from "./User";
import System, {UserKey} from "./System";
import LocationRepo, {
LocationByTagResult,
LocationElementQueryResult,
LocationQueryResult
} from "../repositories/location.repo";
} from "@/electron/database/repositories/location.repository";
import System from "@/electron/database/System";
import {getUserEncryptionKey} from "../keyManager";
export interface SubElement {
id: string;
@@ -30,23 +30,21 @@ export default class Location {
* Récupère toutes les locations pour un utilisateur et un livre donnés.
* @param {string} userId - L'ID de l'utilisateur.
* @param {string} bookId - L'ID du livre.
* @returns {Promise<LocationProps[]>} - Une promesse qui résout un tableau de propriétés de location.
* @returns {LocationProps[]} - Un tableau de propriétés de location.
* @throws {Error} - Lance une erreur si une exception se produit lors de la récupération des locations.
*/
static async getAllLocations(userId: string, bookId: string): Promise<LocationProps[]> {
const locations: LocationQueryResult[] = await LocationRepo.getLocation(userId, bookId);
static getAllLocations(userId: string, bookId: string, lang: 'fr' | 'en' = 'fr'): LocationProps[] {
const locations: LocationQueryResult[] = LocationRepo.getLocation(userId, bookId, lang);
if (!locations || locations.length === 0) return [];
const user = new User(userId);
const userKeys: UserKey[] = await System.getAllUserKeysAndVersions(userId);
const userKey: string = getUserEncryptionKey(userId);
const locationArray: LocationProps[] = [];
for (const record of locations) {
let location = locationArray.find(loc => loc.id === record.loc_id);
if (!location) {
const key: string = await user.getUserKey(record.loc_meta, true, userKeys);
const decryptedName: string = System.decryptDataWithUserKey(record.loc_name, key)/* ton code de décryptage ici avec record.loc_name */;
const decryptedName: string = System.decryptDataWithUserKey(record.loc_name, userKey);
location = {
id: record.loc_id,
name: decryptedName,
@@ -54,14 +52,13 @@ export default class Location {
};
locationArray.push(location);
}
if (record.element_id) {
let element = location.elements.find(elem => elem.id === record.element_id);
if (!element) {
const key: string = await user.getUserKey(record.element_meta, true, userKeys);
const decryptedName: string = System.decryptDataWithUserKey(record.element_name, key)/* ton code de décryptage ici avec record.element_name */;
const decryptedDesc: string = record.element_description ? System.decryptDataWithUserKey(record.element_description, key) : ''/* ton code de décryptage ici avec record.element_description */;
const decryptedName: string = System.decryptDataWithUserKey(record.element_name, userKey);
const decryptedDesc: string = record.element_description ? System.decryptDataWithUserKey(record.element_description, userKey) : '';
element = {
id: record.element_id,
name: decryptedName,
@@ -70,16 +67,15 @@ export default class Location {
};
location.elements.push(element);
}
if (record.sub_element_id) {
const subElementExists = element.subElements.some(sub => sub.id === record.sub_element_id);
if (!subElementExists) {
const key: string = await user.getUserKey(record.sub_elem_meta, true, userKeys);
const decryptedName: string = System.decryptDataWithUserKey(record.sub_elem_name, key)/* ton code de décryptage ici avec record.sub_elem_name */;
const decryptedDesc: string = record.sub_elem_description ? System.decryptDataWithUserKey(record.sub_elem_description, key) : ''/* ton code de décryptage ici avec record.sub_elem_description */;
const decryptedName: string = System.decryptDataWithUserKey(record.sub_elem_name, userKey);
const decryptedDesc: string = record.sub_elem_description ? System.decryptDataWithUserKey(record.sub_elem_description, userKey) : '';
element.subElements.push({
id: record.sub_element_id,
name: decryptedName,
@@ -91,133 +87,120 @@ export default class Location {
}
return locationArray;
}
static async addLocationSection(userId: string, locationName: string, bookId: string): Promise<string> {
const user = new User(userId);
const meta: string = System.encryptDateKey(userId);
const userKey: string = await user.getUserKey(meta, true);
static addLocationSection(userId: string, locationName: string, bookId: string, lang: 'fr' | 'en' = 'fr'): string {
const userKey: string = getUserEncryptionKey(userId);
const originalName: string = System.hashElement(locationName);
const encryptedName: string = System.encryptDataWithUserKey(locationName, userKey);
const locationId: string = System.createUniqueId();
return await LocationRepo.insertLocation(userId, locationId, bookId, encryptedName, originalName, meta);
return LocationRepo.insertLocation(userId, locationId, bookId, encryptedName, originalName, lang);
}
static async addLocationElement(userId: string, locationId: string, elementName: string) {
const user = new User(userId);
const meta: string = System.encryptDateKey(userId);
const userKey: string = await user.getUserKey(meta, true);
static addLocationElement(userId: string, locationId: string, elementName: string, lang: 'fr' | 'en' = 'fr') {
const userKey: string = getUserEncryptionKey(userId);
const originalName: string = System.hashElement(elementName);
const encryptedName: string = System.encryptDataWithUserKey(elementName, userKey);
const elementId: string = System.createUniqueId();
return LocationRepo.insertLocationElement(userId, elementId, locationId, encryptedName, originalName, meta)
return LocationRepo.insertLocationElement(userId, elementId, locationId, encryptedName, originalName, lang)
}
static async addLocationSubElement(userId: string, elementId: string, subElementName: string) {
const user = new User(userId);
const meta: string = System.encryptDateKey(userId);
const userKey: string = await user.getUserKey(meta, true);
static addLocationSubElement(userId: string, elementId: string, subElementName: string, lang: 'fr' | 'en' = 'fr') {
const userKey: string = getUserEncryptionKey(userId);
const originalName: string = System.hashElement(subElementName);
const encryptedName: string = System.encryptDataWithUserKey(subElementName, userKey);
const subElementId: string = System.createUniqueId();
return LocationRepo.insertLocationSubElement(userId, subElementId, elementId, encryptedName, originalName, meta)
return LocationRepo.insertLocationSubElement(userId, subElementId, elementId, encryptedName, originalName, lang)
}
static async updateLocationSection(userId: string, locations: LocationProps[]) {
const user = new User(userId);
const meta: string = System.encryptDateKey(userId);
const userKey: string = await user.getUserKey(meta, true);
static updateLocationSection(userId: string, locations: LocationProps[], lang: 'fr' | 'en' = 'fr') {
const userKey: string = getUserEncryptionKey(userId);
for (const location of locations) {
const originalName: string = System.hashElement(location.name);
const encryptedName: string = System.encryptDataWithUserKey(location.name, userKey);
await LocationRepo.updateLocationSection(userId, location.id, encryptedName, originalName, meta)
LocationRepo.updateLocationSection(userId, location.id, encryptedName, originalName, lang)
for (const element of location.elements) {
const originalName: string = System.hashElement(element.name);
const encryptedName: string = System.encryptDataWithUserKey(element.name, userKey);
const encryptDescription: string = element.description ? System.encryptDataWithUserKey(element.description, userKey) : '';
await LocationRepo.updateLocationElement(userId, element.id, encryptedName, originalName, encryptDescription, meta)
LocationRepo.updateLocationElement(userId, element.id, encryptedName, originalName, encryptDescription, lang)
for (const subElement of element.subElements) {
const originalName: string = System.hashElement(subElement.name);
const encryptedName: string = System.encryptDataWithUserKey(subElement.name, userKey);
const encryptDescription: string = subElement.description ? System.encryptDataWithUserKey(subElement.description, userKey) : '';
await LocationRepo.updateLocationSubElement(userId, subElement.id, encryptedName, originalName, encryptDescription, meta)
LocationRepo.updateLocationSubElement(userId, subElement.id, encryptedName, originalName, encryptDescription, lang)
}
}
}
return {
valid: true,
message: 'Les sections ont été mis à jour.'
message: lang === 'fr' ? 'Les sections ont été mis à jour.' : 'Sections have been updated.'
}
}
static async deleteLocationSection(userId: string, locationId: string) {
return LocationRepo.deleteLocationSection(userId, locationId);
static deleteLocationSection(userId: string, locationId: string, lang: 'fr' | 'en' = 'fr') {
return LocationRepo.deleteLocationSection(userId, locationId, lang);
}
static async deleteLocationElement(userId: string, elementId: string) {
return LocationRepo.deleteLocationElement(userId, elementId);
static deleteLocationElement(userId: string, elementId: string, lang: 'fr' | 'en' = 'fr') {
return LocationRepo.deleteLocationElement(userId, elementId, lang);
}
static async deleteLocationSubElement(userId: string, subElementId: string) {
return LocationRepo.deleteLocationSubElement(userId, subElementId);
static deleteLocationSubElement(userId: string, subElementId: string, lang: 'fr' | 'en' = 'fr') {
return LocationRepo.deleteLocationSubElement(userId, subElementId, lang);
}
static async getLocationTags(userId: string, bookId: string): Promise<SubElement[]> {
const data: LocationElementQueryResult[] = await LocationRepo.fetchLocationTags(userId, bookId);
static getLocationTags(userId: string, bookId: string, lang: 'fr' | 'en' = 'fr'): SubElement[] {
const data: LocationElementQueryResult[] = LocationRepo.fetchLocationTags(userId, bookId, lang);
if (!data || data.length === 0) return [];
const user = new User(userId);
const userKeys: UserKey[] = await System.getAllUserKeysAndVersions(userId);
const userKey: string = getUserEncryptionKey(userId);
const elementCounts = new Map<string, number>();
data.forEach((record: LocationElementQueryResult): void => {
elementCounts.set(record.element_id, (elementCounts.get(record.element_id) || 0) + 1);
});
const subElements: SubElement[] = [];
const processedIds = new Set<string>();
for (const record of data) {
const elementCount: number = elementCounts.get(record.element_id) || 0;
if (elementCount > 1 && record.sub_element_id) {
if (processedIds.has(record.sub_element_id)) continue;
const key: string = await user.getUserKey(record.sub_elem_meta, true, userKeys);
subElements.push({
id: record.sub_element_id,
name: System.decryptDataWithUserKey(record.sub_elem_name, key),
description: record.sub_elem_description ? System.decryptDataWithUserKey(record.sub_elem_description, key) : ''
name: System.decryptDataWithUserKey(record.sub_elem_name, userKey),
description: record.sub_elem_description ? System.decryptDataWithUserKey(record.sub_elem_description, userKey) : ''
});
processedIds.add(record.sub_element_id);
} else if (elementCount === 1 && !record.sub_element_id) {
if (processedIds.has(record.element_id)) continue;
const key: string = await user.getUserKey(record.element_meta, true, userKeys);
subElements.push({
id: record.element_id,
name: System.decryptDataWithUserKey(record.element_name, key),
description: record.element_description ? System.decryptDataWithUserKey(record.element_description, key) : ''
name: System.decryptDataWithUserKey(record.element_name, userKey),
description: record.element_description ? System.decryptDataWithUserKey(record.element_description, userKey) : ''
});
processedIds.add(record.element_id);
}
}
return subElements;
}
static async getLocationsByTags(userId: string, locations: string[]): Promise<Element[]> {
const locationsTags: LocationByTagResult[] = await LocationRepo.fetchLocationsByTags(userId, locations);
static getLocationsByTags(userId: string, locations: string[], lang: 'fr' | 'en' = 'fr'): Element[] {
const locationsTags: LocationByTagResult[] = LocationRepo.fetchLocationsByTags(userId, locations, lang);
if (!locationsTags || locationsTags.length === 0) return [];
const user = new User(userId);
const userKeys: UserKey[] = await System.getAllUserKeysAndVersions(userId);
const userKey: string = getUserEncryptionKey(userId);
const locationTags: Element[] = [];
for (const record of locationsTags) {
let element: Element | undefined = locationTags.find((elem: Element): boolean => elem.name === record.element_name);
if (!element) {
const key: string = await user.getUserKey(record.element_meta, true, userKeys);
const decryptedName: string = System.decryptDataWithUserKey(record.element_name, key);
const decryptedDesc: string = record.element_description ? System.decryptDataWithUserKey(record.element_description, key) : '';
const decryptedName: string = System.decryptDataWithUserKey(record.element_name, userKey);
const decryptedDesc: string = record.element_description ? System.decryptDataWithUserKey(record.element_description, userKey) : '';
element = {
id: record.element_id,
id: '',
name: decryptedName,
description: decryptedDesc,
subElements: []
@@ -227,9 +210,8 @@ export default class Location {
if (record.sub_elem_name) {
const subElementExists: boolean = element.subElements.some(sub => sub.name === record.sub_elem_name);
if (!subElementExists) {
const key: string = await user.getUserKey(record.sub_elem_meta, true, userKeys);
const decryptedName: string = System.decryptDataWithUserKey(record.sub_elem_name, key);
const decryptedDesc: string = record.sub_elem_description ? System.decryptDataWithUserKey(record.sub_elem_description, key) : '';
const decryptedName: string = System.decryptDataWithUserKey(record.sub_elem_name, userKey);
const decryptedDesc: string = record.sub_elem_description ? System.decryptDataWithUserKey(record.sub_elem_description, userKey) : '';
element.subElements.push({
id: '',
name: decryptedName,
@@ -240,8 +222,8 @@ export default class Location {
}
return locationTags;
}
static async locationsDescription(locations: Element[]): Promise<string> {
static locationsDescription(locations: Element[]): string {
return locations.map((location: Element): string => {
const fields: string[] = [];
if (location.name) fields.push(`Nom : ${location.name}`);