From ba417b643eafbfc1ad6cb8473ba32c84144cee1f Mon Sep 17 00:00:00 2001 From: ilham Date: Fri, 17 Dec 2021 00:32:28 +0700 Subject: [PATCH] fix: product --- src/product/product-sub-categories.service.ts | 5 +---- src/product/product.controller.ts | 4 ++-- src/product/product.service.ts | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/product/product-sub-categories.service.ts b/src/product/product-sub-categories.service.ts index eb0aeab..c6c3b8c 100644 --- a/src/product/product-sub-categories.service.ts +++ b/src/product/product-sub-categories.service.ts @@ -47,10 +47,7 @@ export class ProductSubCategoriesService { async findAll(page, category) { const baseQuery = this.productSubCategoriesRepository .createQueryBuilder('product_sub_categories') - .leftJoinAndSelect( - 'product_sub_categories.category', - 'category', - ); + .leftJoinAndSelect('product_sub_categories.category', 'category'); if (category != 'null') { baseQuery.where({ diff --git a/src/product/product.controller.ts b/src/product/product.controller.ts index 38aadc3..312f8c2 100644 --- a/src/product/product.controller.ts +++ b/src/product/product.controller.ts @@ -98,12 +98,12 @@ export class ProductController { @Get('by-categories-all') async findByCategoriesAll( @Query('page') page: number, - @Query('sub-categories') categories: string, + @Query('sub-category') subcategory: string, @Query('supplier') supplier: string, ) { const data = await this.productService.findAllBySubCategories( page, - categories, + subcategory, supplier, ); diff --git a/src/product/product.service.ts b/src/product/product.service.ts index 4e9c770..4cebe51 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -95,19 +95,15 @@ export class ProductService { } async findAllBySubCategories(page, subCategories, supplier) { - if (!supplier) { + if (supplier != 'null' && !supplier) { supplier = await this.supplierService.findByActive(); } const baseQuery = this.productRepository .createQueryBuilder('product') .leftJoin('product.sub_categories', 'sub_categories') - .where( - 'sub_categories.category_id = :id and product.supplier_id = :supplier_id', - { - id: subCategories, - supplier_id: supplier, - }, - ) + .where('product.supplier_id = :supplier_id', { + supplier_id: supplier, + }) .leftJoinAndMapOne( 'product.currentPrice', 'product.priceHistory', @@ -115,6 +111,12 @@ export class ProductService { 'current_price.partner_id is null', ); + if (subCategories != 'null' && !subCategories) { + baseQuery.where('product.sub_categories_id = :id', { + id: subCategories, + }); + } + const data = await baseQuery .skip(page * 10) .take(10)