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.
This commit is contained in:
@@ -12,7 +12,7 @@ import Upload from "../database/models/Upload.js";
|
||||
import GuideLine, {GuideLineAI} from "../database/models/GuideLine.js";
|
||||
import Incident from "../database/models/Incident.js";
|
||||
import PlotPoint from "../database/models/PlotPoint.js";
|
||||
import World, {WorldProps} from "../database/models/World.js";
|
||||
import World, {WorldListResponse, WorldProps} from "../database/models/World.js";
|
||||
|
||||
interface UpdateBookBasicData {
|
||||
title: string;
|
||||
@@ -330,8 +330,8 @@ ipcMain.handle('db:book:issue:remove', createHandler<RemoveIssueData, boolean>(
|
||||
interface GetWorldsData {
|
||||
bookid: string;
|
||||
}
|
||||
ipcMain.handle('db:book:worlds:get', createHandler<GetWorldsData, WorldProps[]>(
|
||||
function(userId: string, data: GetWorldsData, lang: 'fr' | 'en') {
|
||||
ipcMain.handle('db:book:worlds:get', createHandler<GetWorldsData, WorldListResponse>(
|
||||
function(userId: string, data: GetWorldsData, lang: 'fr' | 'en'): WorldListResponse {
|
||||
return World.getWorlds(userId, data.bookid, lang);
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
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';
|
||||
import Character, {CharacterListResponse} from '../database/models/Character.js';
|
||||
import type { CharacterPropsPost, CharacterAttribute } from '../database/models/Character.js';
|
||||
|
||||
interface AddCharacterData {
|
||||
character: CharacterPropsPost;
|
||||
@@ -20,8 +20,8 @@ interface AddAttributeData {
|
||||
interface GetCharacterListData {
|
||||
bookid: string;
|
||||
}
|
||||
ipcMain.handle('db:character:list', createHandler<GetCharacterListData, CharacterProps[]>(
|
||||
function(userId: string, data: GetCharacterListData, lang: 'fr' | 'en'): CharacterProps[] {
|
||||
ipcMain.handle('db:character:list', createHandler<GetCharacterListData, CharacterListResponse>(
|
||||
function(userId: string, data: GetCharacterListData, lang: 'fr' | 'en'): CharacterListResponse {
|
||||
return Character.getCharacterList(userId, data.bookid, lang);
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ipcMain } from 'electron';
|
||||
import { createHandler } from '../database/LocalSystem.js';
|
||||
import Location from '../database/models/Location.js';
|
||||
import Location, {LocationListResponse} from '../database/models/Location.js';
|
||||
import type { LocationProps } from '../database/models/Location.js';
|
||||
|
||||
interface UpdateLocationResponse {
|
||||
@@ -34,8 +34,8 @@ interface UpdateLocationData {
|
||||
interface GetAllLocationsData {
|
||||
bookid: string;
|
||||
}
|
||||
ipcMain.handle('db:location:all', createHandler<GetAllLocationsData, LocationProps[]>(
|
||||
function(userId: string, data: GetAllLocationsData, lang: 'fr' | 'en'): LocationProps[] {
|
||||
ipcMain.handle('db:location:all', createHandler<GetAllLocationsData, LocationListResponse>(
|
||||
function(userId: string, data: GetAllLocationsData, lang: 'fr' | 'en'): LocationListResponse {
|
||||
return Location.getAllLocations(userId, data.bookid, lang);
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user