import { Service } from 'typedi' ; import { OrmRepository } from 'typeorm-typedi-extensions' ; import { Logger , LoggerInterface } from '../../decorators/Logger' ; import { Settings } from '../models/Setting' ; import { SettingsRepository } from '../repositories/SettingsRepository' ; import { Like } from 'typeorm' ; @ Service ( ) export class SettingService { constructor ( @ OrmRepository ( ) private settingsRepository , @ Logger ( __filename ) private log ) { } public findOne ( ) { return this . settingsRepository . findOne ( ) ; } public findAll ( ) { this . log . info ( 'Find all setting' ) ; return this . settingsRepository . find ( ) ; } public list ( limit , select = [ ] , relation = [ ] , whereConditions = [ ] ) { const condition = { } ; if ( select && select . length > 0 ) { condition . select = select ; } if ( relation && relation . length > 0 ) { condition . relations = relation ; } condition . where = { } ; if ( whereConditions && whereConditions . length > 0 ) { whereConditions . forEach ( ( item ) => { const operator = item . op ; if ( operator === 'where' && item . value !== '' ) { condition . where [ item . name ] = item . value ; } else if ( operator === 'like' && item . value !== '' ) { condition . where [ item . name ] = Like ( '%' + item . value + '%' ) ; } } ) ; } if ( limit && limit > 0 ) { condition . take = limit ; } console . log ( condition ) ; return this . settingsRepository . find ( condition ) ; } public async create ( settings ) { const newSettings = await this . settingsRepository . save ( settings ) ; return newSettings ; } public update ( id , settings ) { this . log . info ( 'Update a product' ) ; settings . settingsId = id ; return this . settingsRepository . save ( settings ) ; } public async delete ( id ) { this . log . info ( 'Delete a product' ) ; const newSettings = await this . settingsRepository . delete ( id ) ; return newSettings ; } }