From 892ec58c6a22c21dd6d50d01c796bd12a871f20e Mon Sep 17 00:00:00 2001 From: mfadiln2018 Date: Mon, 9 May 2022 17:29:11 +0700 Subject: [PATCH] Fix: filter sub categories --- src/product/product.service.ts | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/product/product.service.ts b/src/product/product.service.ts index 5cb5745..8220b67 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -296,8 +296,15 @@ export class ProductService { subCategories: string, username: string, ) { + let filterSubCategories; const user = await this.usersService.findOneByUsername(username); + if (subCategories) { + filterSubCategories = subCategories.split(',').map((data) => { + return data.trim(); + }); + } + if (user.partner === null) { throw new HttpException( { @@ -332,13 +339,19 @@ export class ProductService { '(current_price.price + current_price.mark_up_price) as price', ); - if ( - subCategories != 'null' && - subCategories && - subCategories != 'undefined' - ) { - baseQuery.where('product.sub_categories_id = :id', { - id: subCategories, + // if ( + // subCategories != 'null' && + // subCategories && + // subCategories != 'undefined' + // ) { + // baseQuery.where('product.sub_categories_id = :id', { + // id: subCategories, + // }); + // } + + if (subCategories && filterSubCategories.length > 0) { + baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', { + subCategoryId: filterSubCategories, }); }