Feat: add get status from product history status
This commit is contained in:
parent
c6d4b12307
commit
4f03fee759
|
@ -65,6 +65,8 @@ export class Product extends BaseModel {
|
||||||
)
|
)
|
||||||
statusHistory: ProductHistoryStatus;
|
statusHistory: ProductHistoryStatus;
|
||||||
|
|
||||||
|
currentStatus: ProductHistoryStatus;
|
||||||
|
|
||||||
@OneToMany(
|
@OneToMany(
|
||||||
() => {
|
() => {
|
||||||
return ProductHistoryPrice;
|
return ProductHistoryPrice;
|
||||||
|
|
|
@ -194,6 +194,12 @@ export class ProductService {
|
||||||
'current_price',
|
'current_price',
|
||||||
'current_price.end_date is NULL',
|
'current_price.end_date is NULL',
|
||||||
)
|
)
|
||||||
|
.innerJoinAndMapOne(
|
||||||
|
'product.currentStatus',
|
||||||
|
'product.statusHistory',
|
||||||
|
'history_status',
|
||||||
|
'history_status.deleted_at is NULL'
|
||||||
|
)
|
||||||
.select(['product.id'])
|
.select(['product.id'])
|
||||||
.addSelect([
|
.addSelect([
|
||||||
'product.name',
|
'product.name',
|
||||||
|
@ -201,8 +207,8 @@ export class ProductService {
|
||||||
'sub_categories.name',
|
'sub_categories.name',
|
||||||
'supplier.name',
|
'supplier.name',
|
||||||
'category.name',
|
'category.name',
|
||||||
'product.status',
|
|
||||||
])
|
])
|
||||||
|
.addSelect('history_status.status', 'status')
|
||||||
.addSelect('current_price.price', 'price')
|
.addSelect('current_price.price', 'price')
|
||||||
.addSelect('current_price.partner_fee', 'partner_fee')
|
.addSelect('current_price.partner_fee', 'partner_fee')
|
||||||
.addSelect('current_price.admin_price', 'admin_price')
|
.addSelect('current_price.admin_price', 'admin_price')
|
||||||
|
@ -282,7 +288,6 @@ export class ProductService {
|
||||||
'current_price',
|
'current_price',
|
||||||
'current_price.partner_id is NULL and current_price.end_date is NULL',
|
'current_price.partner_id is NULL and current_price.end_date is NULL',
|
||||||
)
|
)
|
||||||
.leftJoin('product.statusHistory', 'status_history')
|
|
||||||
.where(
|
.where(
|
||||||
`product.supplier_id = :supplier_id and status_history.status = 'ACTIVE'`,
|
`product.supplier_id = :supplier_id and status_history.status = 'ACTIVE'`,
|
||||||
{
|
{
|
||||||
|
@ -346,7 +351,6 @@ export class ProductService {
|
||||||
'supplier',
|
'supplier',
|
||||||
'supplier.status = true',
|
'supplier.status = true',
|
||||||
)
|
)
|
||||||
.where(`product.status = 'ACTIVE'`)
|
|
||||||
.innerJoinAndMapOne(
|
.innerJoinAndMapOne(
|
||||||
'product.currentPrice',
|
'product.currentPrice',
|
||||||
'product.priceHistory',
|
'product.priceHistory',
|
||||||
|
@ -356,18 +360,25 @@ export class ProductService {
|
||||||
id_partner: user.partner.id,
|
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([
|
.addSelect([
|
||||||
'product.name',
|
'product.name',
|
||||||
'product.code',
|
'product.code',
|
||||||
'product.type',
|
'product.type',
|
||||||
'product.status',
|
|
||||||
'sub_categories.name',
|
'sub_categories.name',
|
||||||
'current_price.admin_price as admin_price',
|
'current_price.admin_price as admin_price',
|
||||||
'current_price.mark_up_price as markup_price',
|
'current_price.mark_up_price as markup_price',
|
||||||
'current_price.partner_fee as partner_fee',
|
'current_price.partner_fee as partner_fee',
|
||||||
'current_price.price as price',
|
'current_price.price as price',
|
||||||
])
|
])
|
||||||
|
.addSelect('history_status.status', 'status')
|
||||||
// .addSelect(
|
// .addSelect(
|
||||||
// '(current_price.price + current_price.mark_up_price) as price',
|
// '(current_price.price + current_price.mark_up_price) as price',
|
||||||
// );
|
// );
|
||||||
|
@ -386,7 +397,7 @@ export class ProductService {
|
||||||
if (subCategories && filterSubCategories.length > 0) {
|
if (subCategories && filterSubCategories.length > 0) {
|
||||||
baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', {
|
baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', {
|
||||||
subCategoryId: filterSubCategories,
|
subCategoryId: filterSubCategories,
|
||||||
}).andWhere(`product.status = 'ACTIVE'`)
|
}).andWhere(`history_status.status = 'ACTIVE'`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const newData = []
|
const newData = []
|
||||||
|
|
Loading…
Reference in New Issue
Block a user