- 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.
122 lines
4.3 KiB
TypeScript
122 lines
4.3 KiB
TypeScript
import { ipcMain } from 'electron';
|
|
import { createHandler } from '../database/LocalSystem.js';
|
|
import Location, {LocationListResponse} from '../database/models/Location.js';
|
|
import type { LocationProps } from '../database/models/Location.js';
|
|
|
|
interface UpdateLocationResponse {
|
|
valid: boolean;
|
|
message: string;
|
|
}
|
|
|
|
interface AddLocationSectionData {
|
|
locationName: string;
|
|
bookId: string;
|
|
id?: string;
|
|
seriesLocationId?: string | null;
|
|
}
|
|
|
|
interface AddLocationElementData {
|
|
locationId: string;
|
|
elementName: string;
|
|
id?: string;
|
|
}
|
|
|
|
interface AddLocationSubElementData {
|
|
elementId: string;
|
|
subElementName: string;
|
|
id?: string;
|
|
}
|
|
|
|
interface UpdateLocationData {
|
|
locations: LocationProps[];
|
|
}
|
|
|
|
// GET /location/all - Get all locations
|
|
interface GetAllLocationsData {
|
|
bookid: string;
|
|
}
|
|
ipcMain.handle('db:location:all', createHandler<GetAllLocationsData, LocationListResponse>(
|
|
function(userId: string, data: GetAllLocationsData, lang: 'fr' | 'en'): LocationListResponse {
|
|
return Location.getAllLocations(userId, data.bookid, lang);
|
|
}
|
|
)
|
|
);
|
|
|
|
// POST /location/section/add - Add location section
|
|
ipcMain.handle('db:location:section:add', createHandler<AddLocationSectionData, string>(
|
|
function(userId: string, data: AddLocationSectionData, lang: 'fr' | 'en'): string {
|
|
return Location.addLocationSection(userId, data.locationName, data.bookId, lang, data.id, data.seriesLocationId || null);
|
|
}
|
|
)
|
|
);
|
|
|
|
// POST /location/element/add - Add location element
|
|
ipcMain.handle('db:location:element:add', createHandler<AddLocationElementData, string>(
|
|
function(userId: string, data: AddLocationElementData, lang: 'fr' | 'en'): string {
|
|
return Location.addLocationElement(userId, data.locationId, data.elementName, lang, data.id);
|
|
}
|
|
)
|
|
);
|
|
|
|
// POST /location/sub-element/add - Add location sub-element
|
|
ipcMain.handle('db:location:subelement:add', createHandler<AddLocationSubElementData, string>(
|
|
function(userId: string, data: AddLocationSubElementData, lang: 'fr' | 'en'): string {
|
|
return Location.addLocationSubElement(userId, data.elementId, data.subElementName, lang, data.id);
|
|
}
|
|
)
|
|
);
|
|
|
|
// POST /location/update - Update location section
|
|
ipcMain.handle('db:location:update', createHandler<UpdateLocationData, UpdateLocationResponse>(
|
|
function(userId: string, data: UpdateLocationData, lang: 'fr' | 'en'): UpdateLocationResponse {
|
|
return Location.updateLocationSection(userId, data.locations, lang);
|
|
}
|
|
)
|
|
);
|
|
|
|
// POST /location/section/update - Update location section with series link
|
|
interface UpdateSectionWithSeriesLinkData {
|
|
sectionId: string;
|
|
sectionName?: string;
|
|
seriesLocationId?: string | null;
|
|
}
|
|
ipcMain.handle('db:location:section:update', createHandler<UpdateSectionWithSeriesLinkData, boolean>(
|
|
function(userId: string, data: UpdateSectionWithSeriesLinkData, lang: 'fr' | 'en'): boolean {
|
|
return Location.updateSectionWithSeriesLink(userId, data.sectionId, data.sectionName, data.seriesLocationId, lang);
|
|
}
|
|
)
|
|
);
|
|
|
|
// DELETE /location/delete - Delete location section
|
|
interface DeleteLocationData {
|
|
locationId: string;
|
|
}
|
|
ipcMain.handle('db:location:delete', createHandler<DeleteLocationData, boolean>(
|
|
function(userId: string, data: DeleteLocationData, lang: 'fr' | 'en'): boolean {
|
|
return Location.deleteLocationSection(userId, data.locationId, lang);
|
|
}
|
|
)
|
|
);
|
|
|
|
// DELETE /location/element/delete - Delete location element
|
|
interface DeleteLocationElementData {
|
|
elementId: string;
|
|
}
|
|
ipcMain.handle('db:location:element:delete', createHandler<DeleteLocationElementData, boolean>(
|
|
function(userId: string, data: DeleteLocationElementData, lang: 'fr' | 'en'): boolean {
|
|
return Location.deleteLocationElement(userId, data.elementId, lang);
|
|
}
|
|
)
|
|
);
|
|
|
|
// DELETE /location/sub-element/delete - Delete location sub-element
|
|
interface DeleteLocationSubElementData {
|
|
subElementId: string;
|
|
}
|
|
ipcMain.handle('db:location:subelement:delete', createHandler<DeleteLocationSubElementData, boolean>(
|
|
function(userId: string, data: DeleteLocationSubElementData, lang: 'fr' | 'en'): boolean {
|
|
return Location.deleteLocationSubElement(userId, data.subElementId, lang);
|
|
}
|
|
)
|
|
);
|