import { Service } from 'typedi' ; import { OrmRepository } from 'typeorm-typedi-extensions' ; import { Logger , LoggerInterface } from '../../decorators/Logger' ; import { Like } from 'typeorm/index' ; import { ProductImageRepository } from '../repositories/ProductImageRepository' ; import { ProductImage } from '../models/ProductImage' ; @ Service ( ) export class ProductImageService { constructor ( @ OrmRepository ( ) private productImageRepository , @ Logger ( __filename ) private log ) { } public async create ( productImage ) { this . log . info ( 'Create a new productImage ' ) ; return this . productImageRepository . save ( productImage ) ; } public findOne ( productImage ) { return this . productImageRepository . findOne ( productImage ) ; } public findAll ( productImage ) { return this . productImageRepository . find ( productImage ) ; } public update ( id , productImage ) { this . log . info ( 'Update a productImage' ) ; productImage . productImageId = id ; return this . productImageRepository . save ( productImage ) ; } public list ( limit , offset , select = [ ] , search = [ ] , whereConditions = [ ] , 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 ( count ) { return this . productImageRepository . count ( condition ) ; } else { return this . productImageRepository . find ( condition ) ; } } public async delete ( id ) { return await this . productImageRepository . delete ( id ) ; } public async deleteProduct ( id ) { return await this . productImageRepository . delete ( { productId : id } ) ; } }