返回 AiToEarn
service.ts
1 /*
2 * @Author: nevin
3 * @Date: 2025-01-24 17:10:35
4 * @LastEditors: nevin
5 * @Description: 用户服务
6 */
7 import { AppDataSource } from '../../db';
8 import { Injectable } from '../core/decorators';
9 import { Repository } from 'typeorm';
10 import { UserModel } from '../../db/models/user';
11
12 @Injectable()
13 export class UserService {
14 private userRepository: Repository<UserModel>;
15 constructor() {
16 this.userRepository = AppDataSource.getRepository(UserModel);
17 }
18 // 添加用户
19 async addUser(user: UserModel) {
20 return await this.userRepository.save(user);
21 }
22
23 // 获取用户
24 async getUser(id: string) {
25 return await this.userRepository.findOne({ where: { id } });
26 }
27
28 // 获取所有用户
29 async getUsers() {
30 return await this.userRepository.find();
31 }
32 }
33
33 lines TYPESCRIPT