import { Service } from 'typedi' ; import { OrmRepository } from 'typeorm-typedi-extensions' ; import { CategoryPath } from '../models/CategoryPath' ; import { CategoryPathRepository } from '../repositories/CategoryPathRepository' ; import { Like } from 'typeorm/index' ; @ Service ( ) export class CategoryPathService { constructor ( @ OrmRepository ( ) private categoryPathRepository ) { } public async create ( categoryPath ) { return this . categoryPathRepository . save ( categoryPath ) ; } public findOne ( categoryPath ) { return this . categoryPathRepository . findOne ( categoryPath ) ; } public async delete ( id ) { await this . categoryPathRepository . delete ( id ) ; return ; } public list ( limit , offset , select = [ ] , search = [ ] , whereConditions = [ ] , sortOrder , count ) { const condition = { } ; if ( select && select . length > 0 ) { condition . select = select ; } 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 ( sortOrder && sortOrder === 1 ) { condition . order = { sortOrder : 'ASC' , } ; } if ( sortOrder && sortOrder === 2 ) { condition . order = { sortOrder : 'DESC' , } ; } console . log ( condition ) ; if ( count ) { return this . categoryPathRepository . count ( condition ) ; } return this . categoryPathRepository . find ( condition ) ; } public find ( categoryPath ) { return this . categoryPathRepository . find ( categoryPath ) ; } }