fix: product

This commit is contained in:
ilham 2021-12-17 00:32:28 +07:00
parent dbf19eb77a
commit ba417b643e
3 changed files with 13 additions and 14 deletions

View File

@ -47,10 +47,7 @@ export class ProductSubCategoriesService {
async findAll(page, category) { async findAll(page, category) {
const baseQuery = this.productSubCategoriesRepository const baseQuery = this.productSubCategoriesRepository
.createQueryBuilder('product_sub_categories') .createQueryBuilder('product_sub_categories')
.leftJoinAndSelect( .leftJoinAndSelect('product_sub_categories.category', 'category');
'product_sub_categories.category',
'category',
);
if (category != 'null') { if (category != 'null') {
baseQuery.where({ baseQuery.where({

View File

@ -98,12 +98,12 @@ export class ProductController {
@Get('by-categories-all') @Get('by-categories-all')
async findByCategoriesAll( async findByCategoriesAll(
@Query('page') page: number, @Query('page') page: number,
@Query('sub-categories') categories: string, @Query('sub-category') subcategory: string,
@Query('supplier') supplier: string, @Query('supplier') supplier: string,
) { ) {
const data = await this.productService.findAllBySubCategories( const data = await this.productService.findAllBySubCategories(
page, page,
categories, subcategory,
supplier, supplier,
); );

View File

@ -95,19 +95,15 @@ export class ProductService {
} }
async findAllBySubCategories(page, subCategories, supplier) { async findAllBySubCategories(page, subCategories, supplier) {
if (!supplier) { if (supplier != 'null' && !supplier) {
supplier = await this.supplierService.findByActive(); supplier = await this.supplierService.findByActive();
} }
const baseQuery = this.productRepository const baseQuery = this.productRepository
.createQueryBuilder('product') .createQueryBuilder('product')
.leftJoin('product.sub_categories', 'sub_categories') .leftJoin('product.sub_categories', 'sub_categories')
.where( .where('product.supplier_id = :supplier_id', {
'sub_categories.category_id = :id and product.supplier_id = :supplier_id',
{
id: subCategories,
supplier_id: supplier, supplier_id: supplier,
}, })
)
.leftJoinAndMapOne( .leftJoinAndMapOne(
'product.currentPrice', 'product.currentPrice',
'product.priceHistory', 'product.priceHistory',
@ -115,6 +111,12 @@ export class ProductService {
'current_price.partner_id is null', 'current_price.partner_id is null',
); );
if (subCategories != 'null' && !subCategories) {
baseQuery.where('product.sub_categories_id = :id', {
id: subCategories,
});
}
const data = await baseQuery const data = await baseQuery
.skip(page * 10) .skip(page * 10)
.take(10) .take(10)