35 lines
860 B
TypeScript
35 lines
860 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { Repository } from 'typeorm';
|
|
import { GroupService } from '../group/group.service';
|
|
import { User } from './user.entity';
|
|
|
|
@Injectable()
|
|
export class UserService {
|
|
constructor(
|
|
@InjectRepository(User) private readonly userRepository: Repository<User>,
|
|
private readonly groupService: GroupService,
|
|
) {}
|
|
|
|
async getUserById(id: number, relations = []) {
|
|
return this.userRepository.findOne({
|
|
where: { id },
|
|
relations,
|
|
});
|
|
}
|
|
|
|
async getUserBySub(sub: string, relations = []) {
|
|
return this.userRepository.findOne({
|
|
where: { sub },
|
|
relations,
|
|
});
|
|
}
|
|
|
|
async getUserByEmail(email: string, relations = []) {
|
|
return this.userRepository.findOne({
|
|
where: { email },
|
|
relations,
|
|
});
|
|
}
|
|
}
|