import { AuthProviderEnum } from '@notifire/shared' ; import { BaseRepository } from '../base-repository' ; import { UserEntity } from './user.entity' ; import { User } from './user.schema' ; export class UserRepository extends BaseRepository < UserEntity > { constructor ( ) { super ( User , UserEntity ) ; } async findByEmail ( email ) { return this . findOne ( { email , } ) ; } async findUserByToken ( token ) { return await this . findOne ( { resetToken : token , } ) ; } async updatePasswordResetToken ( userId , token ) { return await this . update ( { _id : userId , } , { $set : { resetToken : token , resetTokenDate : new Date ( ) , } , } ) ; } async findByLoginProvider ( profileId , provider ) { return this . findOne ( { 'tokens.providerId' : profileId , 'tokens.provider' : provider , } ) ; } async userExists ( userId ) { return ! ! ( await this . findOne ( { _id : userId , } , '_id' ) ) ; } }