Yield generated for 1005e6a4-6d96-4f9b-94af-e4808abb9124
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

22 lines
683 B

import { EntityRepository, Repository } from 'typeorm';
import { User } from './user.entity';
import { Optional } from 'typescript-optional';
@EntityRepository(User)
export class UserRepository extends Repository<User> {
async findOneById(id: number): Promise<Optional<User>> {
return Optional.ofNullable(
await this.findOne(id, { relations: ['roles'] }),
);
}
async hasUserWithMatchingEmail(email: string): Promise<boolean> {
return (await this.count({ where: { email } })) === 1;
}
async findOneWithEmail(email: string): Promise<Optional<User>> {
return Optional.ofNullable(
await this.findOne({ email: email.toLowerCase() }),
);
}
}