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:
76
electron/ipc/series-world.ipc.ts
Normal file
76
electron/ipc/series-world.ipc.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { ipcMain } from 'electron';
|
||||
import { createHandler } from '../database/LocalSystem.js';
|
||||
import SeriesWorld, { SeriesWorldListProps, SeriesWorldUpdateProps } from '../database/models/SeriesWorld.js';
|
||||
|
||||
interface GetWorldListData {
|
||||
seriesId: string;
|
||||
}
|
||||
|
||||
interface AddWorldData {
|
||||
seriesId: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface UpdateWorldData {
|
||||
worldId: string;
|
||||
name: string;
|
||||
history?: string;
|
||||
politics?: string;
|
||||
economy?: string;
|
||||
religion?: string;
|
||||
languages?: string;
|
||||
}
|
||||
|
||||
interface AddElementData {
|
||||
worldId: string;
|
||||
elementType: number;
|
||||
name: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
interface DeleteElementData {
|
||||
elementId: string;
|
||||
}
|
||||
|
||||
// GET /series/world/list - Get world list
|
||||
ipcMain.handle('db:series:world:list', createHandler<GetWorldListData, SeriesWorldListProps[]>(
|
||||
function(userId: string, data: GetWorldListData, lang: 'fr' | 'en'): SeriesWorldListProps[] {
|
||||
return SeriesWorld.getWorldList(userId, data.seriesId, lang);
|
||||
}
|
||||
));
|
||||
|
||||
// POST /series/world/add - Add world
|
||||
ipcMain.handle('db:series:world:add', createHandler<AddWorldData, string>(
|
||||
function(userId: string, data: AddWorldData, lang: 'fr' | 'en'): string {
|
||||
return SeriesWorld.addWorld(userId, data.seriesId, data.name, lang);
|
||||
}
|
||||
));
|
||||
|
||||
// PATCH /series/world/update - Update world
|
||||
ipcMain.handle('db:series:world:update', createHandler<UpdateWorldData, boolean>(
|
||||
function(userId: string, data: UpdateWorldData, lang: 'fr' | 'en'): boolean {
|
||||
const worldData: SeriesWorldUpdateProps = {
|
||||
name: data.name,
|
||||
history: data.history,
|
||||
politics: data.politics,
|
||||
economy: data.economy,
|
||||
religion: data.religion,
|
||||
languages: data.languages
|
||||
};
|
||||
return SeriesWorld.updateWorld(userId, data.worldId, worldData, lang);
|
||||
}
|
||||
));
|
||||
|
||||
// POST /series/world/element/add - Add element
|
||||
ipcMain.handle('db:series:world:element:add', createHandler<AddElementData, string>(
|
||||
function(userId: string, data: AddElementData, lang: 'fr' | 'en'): string {
|
||||
return SeriesWorld.addElement(userId, data.worldId, data.elementType, data.name, lang, data.description);
|
||||
}
|
||||
));
|
||||
|
||||
// DELETE /series/world/element/delete - Delete element
|
||||
ipcMain.handle('db:series:world:element:delete', createHandler<DeleteElementData, boolean>(
|
||||
function(userId: string, data: DeleteElementData, lang: 'fr' | 'en'): boolean {
|
||||
return SeriesWorld.deleteElement(userId, data.elementId, lang);
|
||||
}
|
||||
));
|
||||
Reference in New Issue
Block a user