fix(SPG-655) Item Rate saat filter harga jadi mengambil base price (kemungkinan ada salah ambil priority
parent
82105e8214
commit
9cd50ad817
|
@ -20,6 +20,16 @@ export enum ORDER_TYPE {
|
||||||
DESC = 'DESC',
|
DESC = 'DESC',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const DAY = [
|
||||||
|
'minggu',
|
||||||
|
'senin',
|
||||||
|
'selasa',
|
||||||
|
'rabu',
|
||||||
|
'kamis',
|
||||||
|
'jumat',
|
||||||
|
'sabtu',
|
||||||
|
];
|
||||||
|
|
||||||
export enum CONNECTION_NAME {
|
export enum CONNECTION_NAME {
|
||||||
DEFAULT = 'default',
|
DEFAULT = 'default',
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
RelationParam,
|
RelationParam,
|
||||||
} from 'src/core/modules/domain/entities/base-filter.entity';
|
} from 'src/core/modules/domain/entities/base-filter.entity';
|
||||||
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
||||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
import { DAY, STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class IndexItemRateManager extends BaseIndexManager<ItemEntity> {
|
export class IndexItemRateManager extends BaseIndexManager<ItemEntity> {
|
||||||
|
@ -26,18 +26,32 @@ export class IndexItemRateManager extends BaseIndexManager<ItemEntity> {
|
||||||
d <= new Date(this.filterParam.end_date);
|
d <= new Date(this.filterParam.end_date);
|
||||||
d.setDate(d.getDate() + 1)
|
d.setDate(d.getDate() + 1)
|
||||||
) {
|
) {
|
||||||
const rate = item['item_rates']?.find(
|
const day: string = DAY[d.getDay()];
|
||||||
(rate) =>
|
const rates = item['item_rates']
|
||||||
|
?.filter((rate) => {
|
||||||
|
const days: string[] = rate.season_period.days ?? [];
|
||||||
|
if (rate.season_period.priority == 2) {
|
||||||
|
return (
|
||||||
rate.season_period?.status == STATUS.ACTIVE &&
|
rate.season_period?.status == STATUS.ACTIVE &&
|
||||||
d >= new Date(rate.season_period.start_date) &&
|
d >= new Date(rate.season_period.start_date) &&
|
||||||
d <= new Date(rate.season_period.end_date),
|
d <= new Date(rate.season_period.end_date) &&
|
||||||
|
days.includes(day)
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
rate.season_period?.status == STATUS.ACTIVE &&
|
||||||
|
d >= new Date(rate.season_period.start_date) &&
|
||||||
|
d <= new Date(rate.season_period.end_date)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.sort((a, b) => a.season_period.priority - b.season_period.priority);
|
||||||
|
|
||||||
prices.push({
|
prices.push({
|
||||||
date: new Date(d),
|
date: new Date(d),
|
||||||
price: rate?.price ?? item.base_price,
|
price: rates[0]?.price ?? item.base_price,
|
||||||
season_type: rate?.season_period?.season_type ?? null,
|
season_type: rates[0]?.season_period?.season_type ?? null,
|
||||||
holiday_name: rate?.season_period?.holiday_name ?? null,
|
holiday_name: rates[0]?.season_period?.holiday_name ?? null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +105,8 @@ export class IndexItemRateManager extends BaseIndexManager<ItemEntity> {
|
||||||
'season_period.holiday_name',
|
'season_period.holiday_name',
|
||||||
'season_period.start_date',
|
'season_period.start_date',
|
||||||
'season_period.end_date',
|
'season_period.end_date',
|
||||||
|
'season_period.priority',
|
||||||
|
'season_period.days',
|
||||||
|
|
||||||
'season_type.id',
|
'season_type.id',
|
||||||
'season_type.name',
|
'season_type.name',
|
||||||
|
|
Loading…
Reference in New Issue