Files
ERitors-Scribe-Desktop/electron/ipc/character.ipc.ts
natreex 71d13e2b12 Refactor IPC handlers to enforce consistent return types and enhance type definitions
- Update return types for IPC handlers in `character.ipc.ts`, `chapter.ipc.ts`, and `location.ipc.ts` for stricter type safety.
- Introduce new type definitions for better structure and clarity.
- Remove redundant console logs and unnecessary comments for cleaner code.
2025-11-18 23:01:52 -05:00

63 lines
2.3 KiB
TypeScript

import { ipcMain } from 'electron';
import { createHandler } from '../database/LocalSystem.js';
import Character from '../database/models/Character.js';
import type { CharacterProps, CharacterPropsPost, CharacterAttribute } from '../database/models/Character.js';
interface AddCharacterData {
character: CharacterPropsPost;
bookId: string;
}
interface AddAttributeData {
characterId: string;
type: string;
name: string;
}
// GET /character/list - Get character list
ipcMain.handle('db:character:list', createHandler<string, CharacterProps[]>(
function(userId: string, bookId: string, lang: 'fr' | 'en'): CharacterProps[] {
return Character.getCharacterList(userId, bookId, lang);
}
)
);
// GET /character/attribute - Get character attributes
ipcMain.handle('db:character:attributes', createHandler<string, CharacterAttribute[]>(
function(userId: string, characterId: string, lang: 'fr' | 'en'): CharacterAttribute[] {
return Character.getAttributes(characterId, userId, lang);
}
)
);
// POST /character/add - Add new character
ipcMain.handle('db:character:create', createHandler<AddCharacterData, string>(
function(userId: string, data: AddCharacterData, lang: 'fr' | 'en'): string {
return Character.addNewCharacter(userId, data.character, data.bookId, lang);
}
)
);
// POST /character/attribute/add - Add attribute to character
ipcMain.handle('db:character:attribute:add', createHandler<AddAttributeData, string>(
function(userId: string, data: AddAttributeData, lang: 'fr' | 'en'): string {
return Character.addNewAttribute(data.characterId, userId, data.type, data.name, lang);
}
)
);
// DELETE /character/attribute/delete - Delete character attribute
ipcMain.handle('db:character:attribute:delete', createHandler<string, boolean>(
function(userId: string, attributeId: string, lang: 'fr' | 'en'): boolean {
return Character.deleteAttribute(userId, attributeId, lang);
}
)
);
// POST /character/update - Update character
ipcMain.handle('db:character:update', createHandler<CharacterPropsPost, boolean>(
function(userId: string, character: CharacterPropsPost, lang: 'fr' | 'en'): boolean {
return Character.updateCharacter(userId, character, lang);
}
)
);