- Introduce `db:user:sync` to synchronize user data with the local database during initialization. - Add `db:user:info` and `db:user:update` IPC handlers for fetching and updating user information. - Update `User` model and repository to support extended user fields and improved structure. - Dynamically import user models in main process to avoid circular dependencies. - Refactor database initialization in the app to include user sync logic with error handling.
27 lines
1005 B
TypeScript
27 lines
1005 B
TypeScript
import { ipcMain } from 'electron';
|
|
import { createHandler } from '../database/LocalSystem.js';
|
|
import User, {UserInfoResponse} from '../database/models/User.js';
|
|
|
|
interface UpdateUserData {
|
|
firstName: string;
|
|
lastName: string;
|
|
username: string;
|
|
email: string;
|
|
authorName?: string;
|
|
}
|
|
|
|
// GET /user/info - Get user info from local DB
|
|
ipcMain.handle('db:user:info', createHandler<void, UserInfoResponse>(
|
|
async function(userId: string, _body: void, _lang: 'fr' | 'en'):Promise<UserInfoResponse> {
|
|
return await User.returnUserInfos(userId);
|
|
}
|
|
));
|
|
|
|
// PUT /user/update - Update user info in local DB
|
|
ipcMain.handle('db:user:update', createHandler<UpdateUserData, boolean>(
|
|
async function(userId: string, data: UpdateUserData, lang: 'fr' | 'en'):Promise<boolean> {
|
|
const userKey = '';
|
|
return await User.updateUserInfos(userKey, userId, data.firstName, data.lastName, data.username, data.email, data.authorName, lang);
|
|
}
|
|
));
|