feat: rewrite filter for product again

This commit is contained in:
caturbgs
2021-12-22 14:19:58 +07:00
parent ff2205ea03
commit d9ca0888e7
3 changed files with 22 additions and 17 deletions

View File

@@ -47,7 +47,14 @@ export class ProductService {
return this.productRepository.findOneOrFail(result.identifiers[0].id);
}
async findAll(page: number, supplier: [], subCategories: []) {
async findAll(page: number, supplier: string, subCategories: string) {
let filterSupplier, filterSubCategories;
if (supplier) {
filterSupplier = supplier.split(',').map((data) => data.trim());
}
if (subCategories) {
filterSubCategories = subCategories.split(',').map((data) => data.trim());
}
// if (supplier.length > 0) {
// const dataSupplier = await this.supplierService.findByActiveAll();
// supplier = dataSupplier.map((item) => item.id);
@@ -78,15 +85,15 @@ export class ProductService {
// .addSelect('current_price.price')
// .addSelect('(current_price.price + current_price.mark_up_price) as mark_up_price');
if (subCategories.length > 0) {
if (subCategories && filterSubCategories.length > 0) {
baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', {
subCategoryId: subCategories,
subCategoryId: filterSubCategories,
});
}
if (supplier.length > 0) {
if (supplier && filterSupplier.length > 0) {
baseQuery.where('supplier.id IN (:...supplierId)', {
supplierId: supplier,
supplierId: filterSupplier,
});
}