feat: add filter on endpoint product by sub category
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
			
		||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
 | 
			
		||||
import { EntityNotFoundError, Repository } from 'typeorm';
 | 
			
		||||
import { EntityNotFoundError, In, Repository } from 'typeorm';
 | 
			
		||||
import { ProductSubCategories } from './entities/product-sub-category.entity';
 | 
			
		||||
import { InjectRepository } from '@nestjs/typeorm';
 | 
			
		||||
import { CreateSubCategoriesProductDto } from './dto/sub-categories/create-sub-categories-product.dto';
 | 
			
		||||
@@ -45,13 +45,19 @@ export class ProductSubCategoriesService {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async findAll(page, category) {
 | 
			
		||||
    let filterCategories = [];
 | 
			
		||||
 | 
			
		||||
    if (category !== 'null') {
 | 
			
		||||
      filterCategories = category.split(',').map((data) => data.trim());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const baseQuery = this.productSubCategoriesRepository
 | 
			
		||||
      .createQueryBuilder('product_sub_categories')
 | 
			
		||||
      .leftJoinAndSelect('product_sub_categories.category', 'category');
 | 
			
		||||
 | 
			
		||||
    if (category != 'null' && category) {
 | 
			
		||||
    if (filterCategories.length > 0) {
 | 
			
		||||
      baseQuery.where({
 | 
			
		||||
        category: category,
 | 
			
		||||
        category: In(filterCategories),
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user