feat: rewrite filter for product again
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user