Feat: add get status from product history status

This commit is contained in:
mfadiln2018 2022-08-29 15:46:02 +07:00
parent c6d4b12307
commit 4f03fee759
2 changed files with 19 additions and 6 deletions

View File

@ -65,6 +65,8 @@ export class Product extends BaseModel {
)
statusHistory: ProductHistoryStatus;
currentStatus: ProductHistoryStatus;
@OneToMany(
() => {
return ProductHistoryPrice;

View File

@ -194,6 +194,12 @@ export class ProductService {
'current_price',
'current_price.end_date is NULL',
)
.innerJoinAndMapOne(
'product.currentStatus',
'product.statusHistory',
'history_status',
'history_status.deleted_at is NULL'
)
.select(['product.id'])
.addSelect([
'product.name',
@ -201,8 +207,8 @@ export class ProductService {
'sub_categories.name',
'supplier.name',
'category.name',
'product.status',
])
.addSelect('history_status.status', 'status')
.addSelect('current_price.price', 'price')
.addSelect('current_price.partner_fee', 'partner_fee')
.addSelect('current_price.admin_price', 'admin_price')
@ -282,7 +288,6 @@ export class ProductService {
'current_price',
'current_price.partner_id is NULL and current_price.end_date is NULL',
)
.leftJoin('product.statusHistory', 'status_history')
.where(
`product.supplier_id = :supplier_id and status_history.status = 'ACTIVE'`,
{
@ -346,7 +351,6 @@ export class ProductService {
'supplier',
'supplier.status = true',
)
.where(`product.status = 'ACTIVE'`)
.innerJoinAndMapOne(
'product.currentPrice',
'product.priceHistory',
@ -356,18 +360,25 @@ export class ProductService {
id_partner: user.partner.id,
},
)
.select(['product.id'])
.innerJoinAndMapOne(
'product.currentStatus',
'product.statusHistory',
'history_status',
'history_status.deleted_at is NULL'
)
.where(`history_status.status = 'ACTIVE'`)
.select(['product.id'])
.addSelect([
'product.name',
'product.code',
'product.type',
'product.status',
'sub_categories.name',
'current_price.admin_price as admin_price',
'current_price.mark_up_price as markup_price',
'current_price.partner_fee as partner_fee',
'current_price.price as price',
])
.addSelect('history_status.status', 'status')
// .addSelect(
// '(current_price.price + current_price.mark_up_price) as price',
// );
@ -386,7 +397,7 @@ export class ProductService {
if (subCategories && filterSubCategories.length > 0) {
baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', {
subCategoryId: filterSubCategories,
}).andWhere(`product.status = 'ACTIVE'`)
}).andWhere(`history_status.status = 'ACTIVE'`)
}
const newData = []