Merge branch 'development' into 'devops-staging'

Draft: Development

See merge request empatnusabangsa/ppob/ppob-backend!71
This commit is contained in:
ilham dwi pratama 2021-12-28 11:29:51 +00:00
commit 39e9b4fabe

View File

@ -88,7 +88,6 @@ export class ProductService {
}, },
}); });
} else { } else {
dataHistoryPrice = await this.productHistoryPrice.findOne({ dataHistoryPrice = await this.productHistoryPrice.findOne({
product: productData, product: productData,
@ -302,31 +301,16 @@ export class ProductService {
const user = await this.usersService.findOneByUsername(username); const user = await this.usersService.findOneByUsername(username);
const supplier = await this.supplierService.findByActive(); 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 const baseQuery = this.productRepository
.createQueryBuilder('product') .createQueryBuilder('product')
.leftJoin('product.sub_categories', 'sub_categories') .leftJoin('product.sub_categories', 'sub_categories')
.where( .where(
`product.sub_categories_id IN (:...subCategoryId) and product.supplier_id = :supplier_id and product.status = 'ACTIVE'`, `product.supplier_id = :supplier_id and product.status = 'ACTIVE'`,
{ {
subCategoryId: filterSubCategories,
supplier_id: supplier.id, supplier_id: supplier.id,
}, },
) )
.leftJoinAndMapOne( .innerJoinAndMapOne(
'product.currentPrice', 'product.currentPrice',
'product.priceHistory', 'product.priceHistory',
'current_price', 'current_price',
@ -341,6 +325,16 @@ export class ProductService {
'(current_price.price + current_price.mark_up_price) as price', '(current_price.price + current_price.mark_up_price) as price',
); );
if (
subCategories != 'null' &&
subCategories &&
subCategories != 'undifined'
) {
baseQuery.where('product.sub_categories_id = :id', {
id: subCategories,
});
}
const data = await baseQuery const data = await baseQuery
.offset(page * 10) .offset(page * 10)
.limit(10) .limit(10)