import { DeepPartial , FindConditions , FindManyOptions , FindOneOptions , RemoveOptions , Repository , SaveOptions , } from 'typeorm' ; import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity' ; type id = number | string ; export class ServiceHelper < T > { constructor ( private readonly repository ) { } public async findAll ( options = { } ) { return await this . repository . find ( options ) ; } public async findOne ( id , options = { } ) { return await this . repository . findOne ( id , options ) ; } public async findOneBy ( where , relations = [ ] ) { return await this . repository . findOne ( { where , relations } ) ; } public async findByIds ( ids , options = { } ) { return await this . repository . findByIds ( ids , options ) ; } public async newModel ( model ) { return this . repository . create ( model ) ; } public async create ( model , options = { } ) { const result = await this . newModel ( model ) ; return await this . save ( result , options ) ; } public async update ( id , partial , options = { } ) { await this . repository . update ( id , partial ) ; return this . findOne ( id , options ) ; } public async save ( model , options = { } ) { return await this . repository . save < T > ( model , options ) ; } public async delete ( id , options = { } ) { const model = this . repository . findOne ( id , options ) ; await this . repository . delete ( id ) ; return model ; } public async remove ( models , options = { } ) { return await this . repository . remove ( models , options ) ; } }