fix: get product for partner and for get
This commit is contained in:
parent
0bb1800696
commit
a0ee6b9040
|
@ -125,13 +125,13 @@ export class ProductController {
|
|||
async findByCategories(
|
||||
@Query('page') page: number,
|
||||
@Query('pageSize') pageSize: number,
|
||||
@Query('categories') categories: string,
|
||||
@Query('sub-category') subcategory: string,
|
||||
@Request() req,
|
||||
) {
|
||||
const data = await this.productService.findAllForPartner(
|
||||
page,
|
||||
pageSize,
|
||||
categories,
|
||||
subcategory,
|
||||
req.user.username,
|
||||
);
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ export class ProductService {
|
|||
'product.currentPrice',
|
||||
'product.priceHistory',
|
||||
'current_price',
|
||||
'current_price.partner_id is null',
|
||||
'current_price.partner_id is null and current_price.end_date is NULL',
|
||||
)
|
||||
.select(['product.id'])
|
||||
.addSelect([
|
||||
|
@ -83,7 +83,9 @@ export class ProductService {
|
|||
'category.name',
|
||||
])
|
||||
.addSelect('current_price.price')
|
||||
.addSelect('(current_price.price + current_price.mark_up_price) as mark_up_price');
|
||||
.addSelect(
|
||||
'(current_price.price + current_price.mark_up_price) as mark_up_price',
|
||||
);
|
||||
|
||||
if (subCategories && filterSubCategories.length > 0) {
|
||||
baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', {
|
||||
|
@ -190,19 +192,33 @@ export class ProductService {
|
|||
async findAllForPartner(
|
||||
page: number,
|
||||
pageSize: number,
|
||||
categories: string,
|
||||
subCategories: string,
|
||||
username: string,
|
||||
) {
|
||||
const user = await this.usersService.findOneByUsername(username);
|
||||
const supplier = await this.supplierService.findByActive();
|
||||
|
||||
let filterSupplier, filterSubCategories;
|
||||
|
||||
if (subCategories) {
|
||||
filterSubCategories = subCategories.split(',').map((data) => data.trim());
|
||||
} else {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Sub Categories not inlcude',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
const baseQuery = this.productRepository
|
||||
.createQueryBuilder('product')
|
||||
.leftJoin('product.sub_categories', 'sub_categories')
|
||||
.where(
|
||||
`sub_categories.category_id = :id and product.supplier_id = :supplier_id and product.status = 'ACTIVE'`,
|
||||
`product.sub_categories_id IN (:...subCategoryId) and product.supplier_id = :supplier_id and product.status = 'ACTIVE'`,
|
||||
{
|
||||
id: categories,
|
||||
subCategoryId: filterSubCategories,
|
||||
supplier_id: supplier.id,
|
||||
},
|
||||
)
|
||||
|
@ -211,13 +227,20 @@ export class ProductService {
|
|||
'product.priceHistory',
|
||||
'current_price',
|
||||
'current_price.partner_id = :id_partner and current_price.end_date is NULL',
|
||||
{
|
||||
id_partner: user.partner.id,
|
||||
},
|
||||
)
|
||||
.setParameter('id_partner', user.partner.id);
|
||||
.select(['product.id'])
|
||||
.addSelect(['product.name', 'product.code', 'sub_categories.name'])
|
||||
.addSelect(
|
||||
'(current_price.price + current_price.mark_up_price) as price',
|
||||
);
|
||||
|
||||
const data = await baseQuery
|
||||
.skip(page * pageSize)
|
||||
.take(pageSize)
|
||||
.getMany();
|
||||
.offset(page * 10)
|
||||
.limit(10)
|
||||
.getRawMany();
|
||||
|
||||
const totalData = await baseQuery.getCount();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user