| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2025-01-20 22:02:54 |
| 4 | * @LastEditTime: 2025-02-06 19:14:12 |
| 5 | * @LastEditors: nevin |
| 6 | * @Description: |
| 7 | */ |
| 8 | import { Controller, Icp, Inject } from '../core/decorators'; |
| 9 | import { UserService } from './service'; |
| 10 | import { UserModel } from '../../db/models/user'; |
| 11 | |
| 12 | @Controller() |
| 13 | export class UserController { |
| 14 | @Inject(UserService) |
| 15 | private readonly userService!: UserService; |
| 16 | |
| 17 | /** |
| 18 | * 添加用户 |
| 19 | */ |
| 20 | @Icp('ICP_USER_ADD') |
| 21 | async addUser( |
| 22 | event: Electron.IpcMainInvokeEvent, |
| 23 | user: UserModel, |
| 24 | ): Promise<UserModel> { |
| 25 | const currUser = { |
| 26 | ...user, |
| 27 | phone: user.phone || user.wxOpenId, |
| 28 | loginTime: new Date(), |
| 29 | }; |
| 30 | await this.userService.addUser(currUser); |
| 31 | return currUser; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * 获取平台存储的所有用户信息 |
| 36 | */ |
| 37 | @Icp('ICP_USER_ALL') |
| 38 | async getUserList(): Promise<UserModel[]> { |
| 39 | return await this.userService.getUsers(); |
| 40 | } |
| 41 | } |
| 42 |