Files
ERitors-Scribe-Desktop/electron/ipc/location.ipc.ts
natreex 3d4feaa680 Refactor IPC handlers, types, and models for streamlined data handling
- Unified return types across IPC handlers (`Character`, `Location`, `World`, and `Book`) for consistency.
- Replaced `BookListProps` with `BookProps` for simplified type usage in components and handlers.
- Cleaned up obsolete `BookListProps` interface and applied consistent typings throughout.
- Updated imports to include revised response types (`CharacterListResponse`, `LocationListResponse`, `WorldListResponse`).
- Adjusted data transformation logic in `BookList` and related components to align with new type definitions.
2026-01-15 16:12:20 -05:00

108 lines
3.7 KiB
TypeScript

import { ipcMain } from 'electron';
import { createHandler } from '../database/LocalSystem.js';
import Location, {LocationListResponse} 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;
id?: string;
}
interface AddLocationElementData {
locationId: string;
elementName: string;
id?: string;
}
interface AddLocationSubElementData {
elementId: string;
subElementName: string;
id?: string;
}
interface UpdateLocationData {
locations: LocationProps[];
}
// GET /location/all - Get all locations
interface GetAllLocationsData {
bookid: string;
}
ipcMain.handle('db:location:all', createHandler<GetAllLocationsData, LocationListResponse>(
function(userId: string, data: GetAllLocationsData, lang: 'fr' | 'en'): LocationListResponse {
return Location.getAllLocations(userId, data.bookid, lang);
}
)
);
// 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);
}
)
);
// POST /location/element/add - Add location element
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, data.id);
}
)
);
// POST /location/sub-element/add - Add location sub-element
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, data.id);
}
)
);
// POST /location/update - Update location section
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
interface DeleteLocationData {
locationId: string;
}
ipcMain.handle('db:location:delete', createHandler<DeleteLocationData, boolean>(
function(userId: string, data: DeleteLocationData, lang: 'fr' | 'en'): boolean {
return Location.deleteLocationSection(userId, data.locationId, lang);
}
)
);
// DELETE /location/element/delete - Delete location element
interface DeleteLocationElementData {
elementId: string;
}
ipcMain.handle('db:location:element:delete', createHandler<DeleteLocationElementData, boolean>(
function(userId: string, data: DeleteLocationElementData, lang: 'fr' | 'en'): boolean {
return Location.deleteLocationElement(userId, data.elementId, lang);
}
)
);
// DELETE /location/sub-element/delete - Delete location sub-element
interface DeleteLocationSubElementData {
subElementId: string;
}
ipcMain.handle('db:location:subelement:delete', createHandler<DeleteLocationSubElementData, boolean>(
function(userId: string, data: DeleteLocationSubElementData, lang: 'fr' | 'en'): boolean {
return Location.deleteLocationSubElement(userId, data.subElementId, lang);
}
)
);