feat: 支持登录、个人信息存储
This commit is contained in:
29
src/modules/auth/repositories/user.repository.ts
Normal file
29
src/modules/auth/repositories/user.repository.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { User } from '../entities/user.entity';
|
||||
import { IUserRepository } from './user.repository.interface';
|
||||
|
||||
@Injectable()
|
||||
export class UserRepository implements IUserRepository {
|
||||
constructor(
|
||||
@InjectRepository(User)
|
||||
private readonly repository: Repository<User>,
|
||||
) {}
|
||||
|
||||
async findById(id: string): Promise<User | null> {
|
||||
return this.repository.findOne({ where: { id } });
|
||||
}
|
||||
|
||||
async findByOpenid(openid: string): Promise<User | null> {
|
||||
return this.repository.findOne({ where: { openid } });
|
||||
}
|
||||
|
||||
create(data: Partial<User>): User {
|
||||
return this.repository.create(data);
|
||||
}
|
||||
|
||||
async save(user: User): Promise<User> {
|
||||
return this.repository.save(user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user