import { AccountEntity } from './model' ; import { AccountsDataEntityMapper } from './accounts.data-entity.mapper' ; import { Account , IRepository } from '@btcp/bootcamp-entities' ; import { Connection , Repository , MoreThanOrEqual } from 'typeorm' ; export class AccountRepository implements IRepository < string , Account > { private _repository : Repository < AccountEntity > ; constructor ( connection ) { this . _repository = connection . getRepository ( AccountEntity ) ; } async create ( entity ) { return await this . _repository . create ( entity ) ; } public async getAll ( ) { return await this . _repository . find ( ) . then ( items => items . map ( e => new AccountsDataEntityMapper ( ) . mapFrom ( e ) ) ) ; } public async get ( id ) { return await this . _repository . findOne ( id ) . then ( e => new AccountsDataEntityMapper ( ) . mapFrom ( e ) ) ; } public async getByQuery ( query ) { return await this . _repository . findOne ( query ) . then ( e => e ? new AccountsDataEntityMapper ( ) . mapFrom ( e ) : null ) ; } public async getByVerification ( verification ) { return await this . _repository . findOne ( { verification , verified : false , verificationExpires : MoreThanOrEqual ( new Date ( ) ) } ) . then ( e => e ? new AccountsDataEntityMapper ( ) . mapFrom ( e ) : null ) ; } public async save ( entity ) { return await this . _repository . save ( entity ) ; } public async delete ( id ) { return await this . _repository . delete ( id ) . then ( deleteResult => deleteResult . affected > 0 ) ; } }