From 71d13e2b127d3008c5526cbcd8ee82efe672a98f Mon Sep 17 00:00:00 2001 From: natreex Date: Tue, 18 Nov 2025 23:01:52 -0500 Subject: [PATCH] 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. --- electron/ipc/book.ipc.ts | 3 ++- electron/ipc/chapter.ipc.ts | 4 ++-- electron/ipc/character.ipc.ts | 8 +++----- electron/ipc/location.ipc.ts | 29 +++++++++++++++++------------ 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/electron/ipc/book.ipc.ts b/electron/ipc/book.ipc.ts index da2d0e5..949f506 100644 --- a/electron/ipc/book.ipc.ts +++ b/electron/ipc/book.ipc.ts @@ -2,6 +2,7 @@ import { ipcMain } from 'electron'; import { createHandler } from '../database/LocalSystem.js'; import Book from '../database/models/Book.js'; import type { BookProps, GuideLine, GuideLineAI, Act, Issue, WorldProps } from '../database/models/Book.js'; +import type { ChapterProps } from '../database/models/Chapter.js'; interface UpdateBookBasicData { title: string; @@ -34,7 +35,7 @@ interface StoryData { interface UpdateStoryData { bookId: string; acts: Act[]; - mainChapters: any[]; // ChapterProps[] from your API + mainChapters: ChapterProps[]; } interface CreateBookData { diff --git a/electron/ipc/chapter.ipc.ts b/electron/ipc/chapter.ipc.ts index 2d4bf3a..5e267a0 100644 --- a/electron/ipc/chapter.ipc.ts +++ b/electron/ipc/chapter.ipc.ts @@ -147,8 +147,8 @@ ipcMain.handle('db:chapter:information:add', createHandler( - function(userId: string, chapterInfoId: string, lang: 'fr' | 'en') { +ipcMain.handle('db:chapter:information:remove', createHandler( + function(userId: string, chapterInfoId: string, lang: 'fr' | 'en'): boolean { return Chapter.removeChapterInformation(userId, chapterInfoId, lang); } ) diff --git a/electron/ipc/character.ipc.ts b/electron/ipc/character.ipc.ts index 96aca07..95ae5c6 100644 --- a/electron/ipc/character.ipc.ts +++ b/electron/ipc/character.ipc.ts @@ -47,8 +47,8 @@ ipcMain.handle('db:character:attribute:add', createHandler( - function(userId: string, attributeId: string, lang: 'fr' | 'en') { +ipcMain.handle('db:character:attribute:delete', createHandler( + function(userId: string, attributeId: string, lang: 'fr' | 'en'): boolean { return Character.deleteAttribute(userId, attributeId, lang); } ) @@ -60,6 +60,4 @@ ipcMain.handle('db:character:update', createHandler return Character.updateCharacter(userId, character, lang); } ) -); - -console.log('[IPC] Character handlers registered'); +); \ No newline at end of file diff --git a/electron/ipc/location.ipc.ts b/electron/ipc/location.ipc.ts index e4d3d43..8b620d7 100644 --- a/electron/ipc/location.ipc.ts +++ b/electron/ipc/location.ipc.ts @@ -3,6 +3,11 @@ import { createHandler } from '../database/LocalSystem.js'; import Location 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; @@ -39,48 +44,48 @@ ipcMain.handle('db:location:section:add', createHandler( - function(userId: string, data: AddLocationElementData, lang: 'fr' | 'en') { +ipcMain.handle('db:location:element:add', createHandler( + function(userId: string, data: AddLocationElementData, lang: 'fr' | 'en'): string { return Location.addLocationElement(userId, data.locationId, data.elementName, lang); } ) ); // POST /location/sub-element/add - Add location sub-element -ipcMain.handle('db:location:subelement:add', createHandler( - function(userId: string, data: AddLocationSubElementData, lang: 'fr' | 'en') { +ipcMain.handle('db:location:subelement:add', createHandler( + function(userId: string, data: AddLocationSubElementData, lang: 'fr' | 'en'): string { return Location.addLocationSubElement(userId, data.elementId, data.subElementName, lang); } ) ); // POST /location/update - Update location section -ipcMain.handle('db:location:update', createHandler( - function(userId: string, data: UpdateLocationData, lang: 'fr' | 'en') { +ipcMain.handle('db:location:update', createHandler( + function(userId: string, data: UpdateLocationData, lang: 'fr' | 'en'): UpdateLocationResponse { return Location.updateLocationSection(userId, data.locations, lang); } ) ); // DELETE /location/delete - Delete location section -ipcMain.handle('db:location:delete', createHandler( - function(userId: string, locationId: string, lang: 'fr' | 'en') { +ipcMain.handle('db:location:delete', createHandler( + function(userId: string, locationId: string, lang: 'fr' | 'en'): boolean { return Location.deleteLocationSection(userId, locationId, lang); } ) ); // DELETE /location/element/delete - Delete location element -ipcMain.handle('db:location:element:delete', createHandler( - function(userId: string, elementId: string, lang: 'fr' | 'en') { +ipcMain.handle('db:location:element:delete', createHandler( + function(userId: string, elementId: string, lang: 'fr' | 'en'): boolean { return Location.deleteLocationElement(userId, elementId, lang); } ) ); // DELETE /location/sub-element/delete - Delete location sub-element -ipcMain.handle('db:location:subelement:delete', createHandler( - function(userId: string, subElementId: string, lang: 'fr' | 'en') { +ipcMain.handle('db:location:subelement:delete', createHandler( + function(userId: string, subElementId: string, lang: 'fr' | 'en'): boolean { return Location.deleteLocationSubElement(userId, subElementId, lang); } )