fix: add coa in supplier

This commit is contained in:
ilham
2021-12-16 15:05:10 +07:00
parent dcad18339b
commit 264b7312ed
5 changed files with 61 additions and 11 deletions

View File

@@ -101,7 +101,7 @@ export class ProductController {
@Query('categories') categories: string,
@Query('supplier') supplier: string,
) {
const data = await this.productService.findAllByCategories(
const data = await this.productService.findAllBySubCategories(
page,
categories,
supplier,

View File

@@ -63,14 +63,45 @@ export class ProductService {
});
}
async findAllByCategories(page, categories, supplier) {
async findAllByCategories(page, subCategories, supplier) {
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: categories,
id: subCategories,
supplier_id: supplier,
},
)
.leftJoinAndMapOne(
'product.currentPrice',
'product.priceHistory',
'current_price',
'current_price.partner_id is null',
);
const data = await baseQuery
.skip(page * 10)
.take(10)
.getMany();
const totalData = await baseQuery.getCount();
return {
data,
count: totalData,
};
}
async findAllBySubCategories(page, subCategories, supplier) {
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,
},
)