import { getRepository , Repository , Not } from 'typeorm' ; import IUsersRepository from '@modules/users/repositories/IUsersRepository' ; import ICreateUserDTO from '@modules/users/dtos/ICreateUserDTO' ; import IFindAllProvidersDTO from '@modules/users/dtos/IFindAllProvidersDTO' ; import User from '../entities/Users' ; class UsersRepository implements IUsersRepository { private ormRepository : Repository < User > ; constructor ( ) { this . ormRepository = getRepository ( User ) ; } public async findById ( id ) { const user = await this . ormRepository . findOne ( id ) ; return user ; } public async findByEmail ( email ) { const user = await this . ormRepository . findOne ( { where : { email } , } ) ; return user ; } public async findAllProviders ( { except_user_id , } ) { let users ; if ( except_user_id ) { users = await this . ormRepository . find ( { where : { id : Not ( except_user_id ) } , } ) ; } else { users = await this . ormRepository . find ( ) ; } return users ; } public async create ( userData ) { const user = this . ormRepository . create ( userData ) ; await this . ormRepository . save ( user ) ; return user ; } public async save ( user ) { return this . ormRepository . save ( user ) ; } } export default UsersRepository ;