import { Service } from 'typedi' ; import { OrmRepository } from 'typeorm-typedi-extensions' ; import { Logger , LoggerInterface } from '../../decorators/Logger' ; import { Like } from 'typeorm/index' ; import { OrderLogRepository } from '../repositories/OrderLogRepository' ; @ Service ( ) export class OrderLogService { constructor ( @ OrmRepository ( ) private orderLogRepository , @ Logger ( __filename ) private log ) { } public async create ( order ) { this . log . info ( 'Create a new orderLog ' ) ; return this . orderLogRepository . save ( order ) ; } public findOne ( whereCondition ) { this . log . info ( 'Find orderLog Detail' ) ; const condition = { } ; if ( whereCondition && whereCondition . length > 0 ) { condition . where = whereCondition [ 0 ] ; condition . relations = whereCondition [ 1 ] . relation ; } else { condition . id = whereCondition ; } return this . orderLogRepository . findOne ( condition ) ; } public update ( id , order ) { order . oderId = id ; return this . orderLogRepository . save ( order ) ; } public list ( limit , offset , search = [ ] , whereConditions = [ ] , count ) { const condition = { } ; condition . where = { } ; if ( whereConditions && whereConditions . length > 0 ) { whereConditions . forEach ( ( item ) => { condition . where [ item . name ] = item . value ; } ) ; } if ( search && search . length > 0 ) { search . forEach ( ( table ) => { const operator = table . op ; if ( operator === 'where' && table . value !== '' ) { condition . where [ table . name ] = table . value ; } else if ( operator === 'like' && table . value !== '' ) { condition . where [ table . name ] = Like ( '%' + table . value + '%' ) ; } } ) ; } if ( limit && limit > 0 ) { condition . take = limit ; condition . skip = offset ; } if ( count ) { return this . orderLogRepository . count ( condition ) ; } else { return this . orderLogRepository . find ( condition ) ; } } public async delete ( id ) { return await this . orderLogRepository . delete ( id ) ; } public find ( ) { return this . orderLogRepository . find ( ) ; } }