diff --git a/src/product/product-sub-categories.service.ts b/src/product/product-sub-categories.service.ts index 2d87321..be2c2e7 100644 --- a/src/product/product-sub-categories.service.ts +++ b/src/product/product-sub-categories.service.ts @@ -44,20 +44,14 @@ export class ProductSubCategoriesService { ); } - async findAll(page, category) { - let filterCategories = []; - - if (category !== 'null') { - filterCategories = category.split(',').map((data) => data.trim()); - } - + async findAll(page, category: []) { const baseQuery = this.productSubCategoriesRepository .createQueryBuilder('product_sub_categories') .leftJoinAndSelect('product_sub_categories.category', 'category'); - if (filterCategories.length > 0) { + if (category.length > 0) { baseQuery.where({ - category: In(filterCategories), + category: In(category), }); } diff --git a/src/product/product.controller.ts b/src/product/product.controller.ts index 52d3c0e..0539d81 100644 --- a/src/product/product.controller.ts +++ b/src/product/product.controller.ts @@ -75,7 +75,11 @@ export class ProductController { @Query('sub-category') subcategory: string, @Query('supplier') supplier: string, ) { - const data = await this.productService.findAll(page, supplier, subcategory); + const data = await this.productService.findAll( + page, + JSON.parse(supplier), + JSON.parse(subcategory), + ); return { ...data, @@ -155,7 +159,10 @@ export class ProductController { @Query('page') page: number, @Query('category') category: string, ) { - const data = await this.productSubCategoriesService.findAll(page, category); + const data = await this.productSubCategoriesService.findAll( + page, + JSON.parse(category), + ); return { ...data, diff --git a/src/product/product.service.ts b/src/product/product.service.ts index 007a995..2a0cb36 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -47,16 +47,7 @@ export class ProductService { return this.productRepository.findOneOrFail(result.identifiers[0].id); } - async findAll(page: number, supplier: string, subCategories: string) { - let filterSupplier = []; - let filterSubCategories = []; - - if (supplier !== 'null') { - filterSupplier = supplier.split(',').map((data) => data.trim()); - } - if (subCategories !== 'null') { - filterSubCategories = subCategories.split(',').map((data) => data.trim()); - } + async findAll(page: number, supplier: [], subCategories: []) { // if (supplier.length > 0) { // const dataSupplier = await this.supplierService.findByActiveAll(); // supplier = dataSupplier.map((item) => item.id); @@ -87,15 +78,15 @@ export class ProductService { // .addSelect('current_price.price') // .addSelect('(current_price.price + current_price.mark_up_price) as mark_up_price'); - if (filterSubCategories.length > 0) { + if (subCategories.length > 0) { baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', { - subCategoryId: filterSubCategories, + subCategoryId: subCategories, }); } - if (filterSupplier.length > 0) { + if (supplier.length > 0) { baseQuery.where('supplier.id IN (:...supplierId)', { - supplierId: filterSupplier, + supplierId: supplier, }); }