Add user data synchronization and database IPC handlers

- 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.
This commit is contained in:
natreex
2025-11-18 22:17:22 -05:00
parent 004008cc13
commit 0bafaadecc
5 changed files with 128 additions and 9 deletions

26
electron/ipc/user.ipc.ts Normal file
View File

@@ -0,0 +1,26 @@
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);
}
));