fix: product
This commit is contained in:
parent
dbf19eb77a
commit
ba417b643e
|
@ -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({
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user