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:
26
electron/ipc/user.ipc.ts
Normal file
26
electron/ipc/user.ipc.ts
Normal 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);
|
||||
}
|
||||
));
|
||||
Reference in New Issue
Block a user