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:
natreex
2026-01-26 19:57:56 -05:00
parent 2359638cb0
commit cec5830360
35 changed files with 5483 additions and 203 deletions

View File

@@ -82,6 +82,7 @@ interface AddWorldData {
bookId: string;
worldName: string;
id?: string;
seriesWorldId?: string | null;
}
interface AddWorldElementData {
@@ -113,7 +114,7 @@ interface UpdateWorldData {
interface UpdateBookToolData {
bookId: string;
toolName: 'characters' | 'worlds' | 'locations';
toolName: 'characters' | 'worlds' | 'locations' | 'spells';
enabled: boolean;
}
@@ -340,7 +341,7 @@ ipcMain.handle('db:book:worlds:get', createHandler<GetWorldsData, WorldListRespo
// POST /book/world/add - Add world
ipcMain.handle('db:book:world:add', createHandler<AddWorldData, string>(
function(userId: string, data: AddWorldData, lang: 'fr' | 'en') {
return World.addNewWorld(userId, data.bookId, data.worldName, lang, data.id);
return World.addNewWorld(userId, data.bookId, data.worldName, lang, data.id, data.seriesWorldId || null);
}
)
);

View File

@@ -12,6 +12,7 @@ interface AddLocationSectionData {
locationName: string;
bookId: string;
id?: string;
seriesLocationId?: string | null;
}
interface AddLocationElementData {
@@ -44,7 +45,7 @@ ipcMain.handle('db:location:all', createHandler<GetAllLocationsData, LocationLis
// 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);
return Location.addLocationSection(userId, data.locationName, data.bookId, lang, data.id, data.seriesLocationId || null);
}
)
);
@@ -73,6 +74,19 @@ ipcMain.handle('db:location:update', createHandler<UpdateLocationData, UpdateLoc
)
);
// 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;

View File

@@ -0,0 +1,83 @@
import { ipcMain } from 'electron';
import { createHandler } from '../database/LocalSystem.js';
import SeriesCharacter, { SeriesCharacterPropsPost, SeriesCharacterListProps, CharacterAttributesResponse } from '../database/models/SeriesCharacter.js';
interface GetCharacterListData {
seriesId: string;
}
interface GetCharacterAttributesData {
characterId: string;
}
interface AddCharacterData {
seriesId: string;
character: SeriesCharacterPropsPost;
}
interface UpdateCharacterData {
character: SeriesCharacterPropsPost;
}
interface DeleteCharacterData {
characterId: string;
}
interface AddAttributeData {
characterId: string;
type: string;
name: string;
}
interface DeleteAttributeData {
attributeId: string;
}
// GET /series/character/list - Get character list
ipcMain.handle('db:series:character:list', createHandler<GetCharacterListData, SeriesCharacterListProps[]>(
function(userId: string, data: GetCharacterListData, lang: 'fr' | 'en'): SeriesCharacterListProps[] {
return SeriesCharacter.getCharacterList(userId, data.seriesId, lang);
}
));
// GET /series/character/attribute - Get character attributes
ipcMain.handle('db:series:character:attributes', createHandler<GetCharacterAttributesData, CharacterAttributesResponse>(
function(userId: string, data: GetCharacterAttributesData, lang: 'fr' | 'en'): CharacterAttributesResponse {
return SeriesCharacter.getCharacterAttributes(userId, data.characterId, lang);
}
));
// POST /series/character/add - Add new character
ipcMain.handle('db:series:character:add', createHandler<AddCharacterData, string>(
function(userId: string, data: AddCharacterData, lang: 'fr' | 'en'): string {
return SeriesCharacter.addNewCharacter(userId, data.character, data.seriesId, lang);
}
));
// PATCH /series/character/update - Update character
ipcMain.handle('db:series:character:update', createHandler<UpdateCharacterData, boolean>(
function(userId: string, data: UpdateCharacterData, lang: 'fr' | 'en'): boolean {
return SeriesCharacter.updateCharacter(userId, data.character, lang);
}
));
// DELETE /series/character/delete - Delete character
ipcMain.handle('db:series:character:delete', createHandler<DeleteCharacterData, boolean>(
function(userId: string, data: DeleteCharacterData, lang: 'fr' | 'en'): boolean {
return SeriesCharacter.deleteCharacter(userId, data.characterId, lang);
}
));
// POST /series/character/attribute/add - Add attribute
ipcMain.handle('db:series:character:attribute:add', createHandler<AddAttributeData, string>(
function(userId: string, data: AddAttributeData, lang: 'fr' | 'en'): string {
return SeriesCharacter.addNewAttribute(data.characterId, userId, data.type, data.name, lang);
}
));
// DELETE /series/character/attribute/delete - Delete attribute
ipcMain.handle('db:series:character:attribute:delete', createHandler<DeleteAttributeData, boolean>(
function(userId: string, data: DeleteAttributeData, lang: 'fr' | 'en'): boolean {
return SeriesCharacter.deleteAttribute(userId, data.attributeId, lang);
}
));

View File

@@ -0,0 +1,85 @@
import { ipcMain } from 'electron';
import { createHandler } from '../database/LocalSystem.js';
import SeriesLocation, { SeriesLocationListProps } from '../database/models/SeriesLocation.js';
interface GetLocationListData {
seriesId: string;
}
interface AddLocationSectionData {
seriesId: string;
name: string;
}
interface AddElementData {
locationId: string;
name: string;
description?: string;
}
interface AddSubElementData {
elementId: string;
name: string;
description?: string;
}
interface DeleteLocationData {
locationId: string;
}
interface DeleteElementData {
elementId: string;
}
interface DeleteSubElementData {
subElementId: string;
}
// GET /series/location/list - Get location list
ipcMain.handle('db:series:location:list', createHandler<GetLocationListData, SeriesLocationListProps[]>(
function(userId: string, data: GetLocationListData, lang: 'fr' | 'en'): SeriesLocationListProps[] {
return SeriesLocation.getLocationList(userId, data.seriesId, lang);
}
));
// POST /series/location/section/add - Add location section
ipcMain.handle('db:series:location:section:add', createHandler<AddLocationSectionData, string>(
function(userId: string, data: AddLocationSectionData, lang: 'fr' | 'en'): string {
return SeriesLocation.addLocationSection(userId, data.seriesId, data.name, lang);
}
));
// POST /series/location/element/add - Add element
ipcMain.handle('db:series:location:element:add', createHandler<AddElementData, string>(
function(userId: string, data: AddElementData, lang: 'fr' | 'en'): string {
return SeriesLocation.addElement(userId, data.locationId, data.name, lang, data.description);
}
));
// POST /series/location/sub-element/add - Add sub-element
ipcMain.handle('db:series:location:subelement:add', createHandler<AddSubElementData, string>(
function(userId: string, data: AddSubElementData, lang: 'fr' | 'en'): string {
return SeriesLocation.addSubElement(userId, data.elementId, data.name, lang, data.description);
}
));
// DELETE /series/location/delete - Delete location
ipcMain.handle('db:series:location:delete', createHandler<DeleteLocationData, boolean>(
function(userId: string, data: DeleteLocationData, lang: 'fr' | 'en'): boolean {
return SeriesLocation.deleteLocation(userId, data.locationId, lang);
}
));
// DELETE /series/location/element/delete - Delete element
ipcMain.handle('db:series:location:element:delete', createHandler<DeleteElementData, boolean>(
function(userId: string, data: DeleteElementData, lang: 'fr' | 'en'): boolean {
return SeriesLocation.deleteElement(userId, data.elementId, lang);
}
));
// DELETE /series/location/sub-element/delete - Delete sub-element
ipcMain.handle('db:series:location:subelement:delete', createHandler<DeleteSubElementData, boolean>(
function(userId: string, data: DeleteSubElementData, lang: 'fr' | 'en'): boolean {
return SeriesLocation.deleteSubElement(userId, data.subElementId, lang);
}
));

View File

@@ -0,0 +1,111 @@
import { ipcMain } from 'electron';
import { createHandler } from '../database/LocalSystem.js';
import SeriesSpell, { SeriesSpellListResponse, SeriesSpellDetailProps } from '../database/models/SeriesSpell.js';
interface GetSpellListData {
seriesId: string;
}
interface GetSpellDetailData {
spellId: string;
}
interface AddSpellData {
seriesId: string;
name: string;
description?: string | null;
appearance?: string | null;
tags?: string[];
powerLevel?: string | null;
components?: string | null;
limitations?: string | null;
notes?: string | null;
}
interface UpdateSpellData {
id: string;
name: string;
description?: string | null;
appearance?: string | null;
tags?: string[];
powerLevel?: string | null;
components?: string | null;
limitations?: string | null;
notes?: string | null;
}
interface DeleteSpellData {
spellId: string;
}
interface AddTagData {
seriesId: string;
name: string;
color?: string | null;
}
interface UpdateTagData {
tagId: string;
name: string;
color?: string | null;
}
interface DeleteTagData {
tagId: string;
}
// GET /series/spell/list - Get spell list
ipcMain.handle('db:series:spell:list', createHandler<GetSpellListData, SeriesSpellListResponse>(
function(userId: string, data: GetSpellListData, lang: 'fr' | 'en'): SeriesSpellListResponse {
return SeriesSpell.getSpellList(userId, data.seriesId, lang);
}
));
// GET /series/spell/detail - Get spell detail
ipcMain.handle('db:series:spell:detail', createHandler<GetSpellDetailData, SeriesSpellDetailProps>(
function(userId: string, data: GetSpellDetailData, lang: 'fr' | 'en'): SeriesSpellDetailProps {
return SeriesSpell.getSpellDetail(userId, data.spellId, lang);
}
));
// POST /series/spell/add - Add spell
ipcMain.handle('db:series:spell:add', createHandler<AddSpellData, string>(
function(userId: string, data: AddSpellData, lang: 'fr' | 'en'): string {
return SeriesSpell.addSpell(userId, data.seriesId, data.name, lang, data.description, data.appearance, data.tags, data.powerLevel, data.components, data.limitations, data.notes);
}
));
// PUT /series/spell/update - Update spell
ipcMain.handle('db:series:spell:update', createHandler<UpdateSpellData, boolean>(
function(userId: string, data: UpdateSpellData, lang: 'fr' | 'en'): boolean {
return SeriesSpell.updateSpell(userId, data.id, data.name, lang, data.description, data.appearance, data.tags, data.powerLevel, data.components, data.limitations, data.notes);
}
));
// DELETE /series/spell/delete - Delete spell
ipcMain.handle('db:series:spell:delete', createHandler<DeleteSpellData, boolean>(
function(userId: string, data: DeleteSpellData, lang: 'fr' | 'en'): boolean {
return SeriesSpell.deleteSpell(userId, data.spellId, lang);
}
));
// POST /series/spell/tag/add - Add tag
ipcMain.handle('db:series:spell:tag:add', createHandler<AddTagData, string>(
function(userId: string, data: AddTagData, lang: 'fr' | 'en'): string {
return SeriesSpell.addTag(userId, data.seriesId, data.name, lang, data.color);
}
));
// PUT /series/spell/tag/update - Update tag
ipcMain.handle('db:series:spell:tag:update', createHandler<UpdateTagData, boolean>(
function(userId: string, data: UpdateTagData, lang: 'fr' | 'en'): boolean {
return SeriesSpell.updateTag(userId, data.tagId, data.name, lang, data.color);
}
));
// DELETE /series/spell/tag/delete - Delete tag
ipcMain.handle('db:series:spell:tag:delete', createHandler<DeleteTagData, boolean>(
function(userId: string, data: DeleteTagData, lang: 'fr' | 'en'): boolean {
return SeriesSpell.deleteTag(userId, data.tagId, lang);
}
));

View File

@@ -0,0 +1,24 @@
import { ipcMain } from 'electron';
import { createHandler } from '../database/LocalSystem.js';
import SeriesSync, { SeriesSyncUploadPayload, SeriesSyncResult } from '../database/models/SeriesSync.js';
import { SyncElementType } from '../database/repositories/series-sync.repo.js';
interface UploadToSeriesData {
type: SyncElementType;
bookElementId: string;
field: string;
value: string;
}
// POST /series/sync/upload - Upload field to series
ipcMain.handle('db:series:sync:upload', createHandler<UploadToSeriesData, SeriesSyncResult>(
function(userId: string, data: UploadToSeriesData, lang: 'fr' | 'en'): SeriesSyncResult {
const payload: SeriesSyncUploadPayload = {
type: data.type,
bookElementId: data.bookElementId,
field: data.field,
value: data.value || ''
};
return SeriesSync.uploadFieldToSeries(userId, payload, lang);
}
));

View 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);
}
));

117
electron/ipc/series.ipc.ts Normal file
View File

@@ -0,0 +1,117 @@
import { ipcMain } from 'electron';
import { createHandler } from '../database/LocalSystem.js';
import Series, { BooksOrderPost, SeriesDetailProps, SeriesListItemProps, SeriesBookProps } from '../database/models/Series.js';
interface CreateSeriesData {
name: string;
description?: string;
bookIds?: string[];
}
interface UpdateSeriesData {
seriesId: string;
name: string;
description?: string;
}
interface DeleteSeriesData {
seriesId: string;
}
interface GetSeriesDetailData {
seriesId: string;
}
interface AddBookToSeriesData {
seriesId: string;
bookId: string;
order?: number;
}
interface RemoveBookFromSeriesData {
seriesId: string;
bookId: string;
}
interface UpdateBooksOrderData {
seriesId: string;
booksOrder: BooksOrderPost[];
}
interface GetSeriesForBookData {
bookId: string;
}
interface GetSeriesBooksData {
seriesId: string;
}
// GET /series/list - Get all series
ipcMain.handle('db:series:list', createHandler<void, SeriesListItemProps[]>(
async function(userId: string, _body: void, lang: 'fr' | 'en'): Promise<SeriesListItemProps[]> {
return await Series.getSeriesList(userId, lang);
}
));
// GET /series/detail - Get series detail
ipcMain.handle('db:series:detail', createHandler<GetSeriesDetailData, SeriesDetailProps>(
async function(userId: string, data: GetSeriesDetailData, lang: 'fr' | 'en'): Promise<SeriesDetailProps> {
return await Series.getSeriesDetail(userId, data.seriesId, lang);
}
));
// POST /series/add - Create new series
ipcMain.handle('db:series:create', createHandler<CreateSeriesData, string>(
async function(userId: string, data: CreateSeriesData, lang: 'fr' | 'en'): Promise<string> {
return await Series.createSeries(userId, data.name, data.description || '', lang, data.bookIds);
}
));
// PUT /series/update - Update series
ipcMain.handle('db:series:update', createHandler<UpdateSeriesData, boolean>(
async function(userId: string, data: UpdateSeriesData, lang: 'fr' | 'en'): Promise<boolean> {
return await Series.updateSeries(userId, data.seriesId, data.name, data.description || '', lang);
}
));
// DELETE /series/delete - Delete series
ipcMain.handle('db:series:delete', createHandler<DeleteSeriesData, boolean>(
async function(userId: string, data: DeleteSeriesData, lang: 'fr' | 'en'): Promise<boolean> {
return await Series.deleteSeries(userId, data.seriesId, lang);
}
));
// GET /series/book/list - Get books in series
ipcMain.handle('db:series:books', createHandler<GetSeriesBooksData, SeriesBookProps[]>(
async function(userId: string, data: GetSeriesBooksData, lang: 'fr' | 'en'): Promise<SeriesBookProps[]> {
return await Series.getSeriesBooks(userId, data.seriesId, lang);
}
));
// POST /series/book/add - Add book to series
ipcMain.handle('db:series:book:add', createHandler<AddBookToSeriesData, boolean>(
async function(userId: string, data: AddBookToSeriesData, lang: 'fr' | 'en'): Promise<boolean> {
return await Series.addBookToSeries(userId, data.seriesId, data.bookId, data.order ?? 1, lang);
}
));
// DELETE /series/book/remove - Remove book from series
ipcMain.handle('db:series:book:remove', createHandler<RemoveBookFromSeriesData, boolean>(
async function(userId: string, data: RemoveBookFromSeriesData, lang: 'fr' | 'en'): Promise<boolean> {
return await Series.removeBookFromSeries(userId, data.seriesId, data.bookId, lang);
}
));
// PUT /series/book/reorder - Reorder books in series
ipcMain.handle('db:series:book:reorder', createHandler<UpdateBooksOrderData, boolean>(
async function(userId: string, data: UpdateBooksOrderData, lang: 'fr' | 'en'): Promise<boolean> {
return await Series.updateBooksOrder(userId, data.seriesId, data.booksOrder, lang);
}
));
// GET /series/for-book - Get series ID for a book
ipcMain.handle('db:series:forBook', createHandler<GetSeriesForBookData, string | null>(
function(_userId: string, data: GetSeriesForBookData, _lang: 'fr' | 'en'): string | null {
return Series.getSeriesIdForBook(data.bookId);
}
));

View File

@@ -19,6 +19,7 @@ interface SpellPost {
components?: string | null;
limitations?: string | null;
notes?: string | null;
seriesSpellId?: string | null;
}
interface GetSpellListData {
@@ -115,6 +116,7 @@ ipcMain.handle(
spell.notes || null,
spell.id,
lang,
spell.seriesSpellId || null,
);
return result.id;
},
@@ -139,6 +141,7 @@ ipcMain.handle(
spell.limitations || null,
spell.notes || null,
lang,
spell.seriesSpellId || null,
);
},
),