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.
This commit is contained in:
@@ -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<AddLocationSectionData,
|
||||
);
|
||||
|
||||
// POST /location/element/add - Add location element
|
||||
ipcMain.handle('db:location:element:add', createHandler<AddLocationElementData, any>(
|
||||
function(userId: string, data: AddLocationElementData, lang: 'fr' | 'en') {
|
||||
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);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// POST /location/sub-element/add - Add location sub-element
|
||||
ipcMain.handle('db:location:subelement:add', createHandler<AddLocationSubElementData, any>(
|
||||
function(userId: string, data: AddLocationSubElementData, lang: 'fr' | 'en') {
|
||||
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);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// POST /location/update - Update location section
|
||||
ipcMain.handle('db:location:update', createHandler<UpdateLocationData, any>(
|
||||
function(userId: string, data: UpdateLocationData, lang: 'fr' | 'en') {
|
||||
ipcMain.handle('db:location:update', createHandler<UpdateLocationData, UpdateLocationResponse>(
|
||||
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<string, any>(
|
||||
function(userId: string, locationId: string, lang: 'fr' | 'en') {
|
||||
ipcMain.handle('db:location:delete', createHandler<string, boolean>(
|
||||
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<string, any>(
|
||||
function(userId: string, elementId: string, lang: 'fr' | 'en') {
|
||||
ipcMain.handle('db:location:element:delete', createHandler<string, boolean>(
|
||||
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<string, any>(
|
||||
function(userId: string, subElementId: string, lang: 'fr' | 'en') {
|
||||
ipcMain.handle('db:location:subelement:delete', createHandler<string, boolean>(
|
||||
function(userId: string, subElementId: string, lang: 'fr' | 'en'): boolean {
|
||||
return Location.deleteLocationSubElement(userId, subElementId, lang);
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user