fix(SPG-602) Harga Item belum mengambil harga season periode
parent
b574d3a39d
commit
78ae2a5d8e
|
@ -6,6 +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';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class IndexItemRateManager extends BaseIndexManager<ItemEntity> {
|
export class IndexItemRateManager extends BaseIndexManager<ItemEntity> {
|
||||||
|
@ -27,6 +28,7 @@ export class IndexItemRateManager extends BaseIndexManager<ItemEntity> {
|
||||||
) {
|
) {
|
||||||
const rate = item['item_rates']?.find(
|
const rate = item['item_rates']?.find(
|
||||||
(rate) =>
|
(rate) =>
|
||||||
|
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),
|
||||||
);
|
);
|
||||||
|
@ -84,6 +86,7 @@ export class IndexItemRateManager extends BaseIndexManager<ItemEntity> {
|
||||||
'item_rates.price',
|
'item_rates.price',
|
||||||
|
|
||||||
'season_period.id',
|
'season_period.id',
|
||||||
|
'season_period.status',
|
||||||
'season_period.holiday_name',
|
'season_period.holiday_name',
|
||||||
'season_period.start_date',
|
'season_period.start_date',
|
||||||
'season_period.end_date',
|
'season_period.end_date',
|
||||||
|
|
|
@ -6,4 +6,5 @@ export interface FilterItemEntity extends BaseFilterEntity {
|
||||||
limit_types: string[];
|
limit_types: string[];
|
||||||
tenant_ids: string[];
|
tenant_ids: string[];
|
||||||
all_item: boolean;
|
all_item: boolean;
|
||||||
|
season_period_ids: string[];
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { ItemRateEntity } from 'src/modules/item-related/item-rate/domain/entiti
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class IndexItemRatesManager extends BaseIndexManager<ItemRateEntity> {
|
export class IndexItemRatesManager extends BaseIndexManager<ItemRateEntity> {
|
||||||
async prepareData(): Promise<void> {
|
async prepareData(): Promise<void> {
|
||||||
this.filterParam.order_by = `${this.tableName}.id`;
|
this.filterParam.order_by = `season_period.id`;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,9 +38,11 @@ export class IndexItemRatesManager extends BaseIndexManager<ItemRateEntity> {
|
||||||
get selects(): string[] {
|
get selects(): string[] {
|
||||||
return [
|
return [
|
||||||
`${this.tableName}.id`,
|
`${this.tableName}.id`,
|
||||||
|
`${this.tableName}.item_id`,
|
||||||
`${this.tableName}.price`,
|
`${this.tableName}.price`,
|
||||||
|
|
||||||
`season_period.id`,
|
`season_period.id`,
|
||||||
|
`season_period.priority`,
|
||||||
`season_period.created_at`,
|
`season_period.created_at`,
|
||||||
`season_period.creator_name`,
|
`season_period.creator_name`,
|
||||||
`season_period.editor_name`,
|
`season_period.editor_name`,
|
||||||
|
@ -68,20 +70,25 @@ export class IndexItemRatesManager extends BaseIndexManager<ItemRateEntity> {
|
||||||
itemIds: this.filterParam.item_ids,
|
itemIds: this.filterParam.item_ids,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (this.filterParam.start_date) {
|
|
||||||
queryBuilder.andWhere(`season_period.start_date BETWEEN :from AND :to`, {
|
if (this.filterParam.season_period_ids) {
|
||||||
from: this.filterParam.start_date,
|
queryBuilder.andWhere(`season_period.id In (:...itemIds)`, {
|
||||||
to: this.filterParam.end_date,
|
itemIds: this.filterParam.season_period_ids,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.filterParam.end_date) {
|
if (this.filterParam.start_date) {
|
||||||
queryBuilder.andWhere(`season_period.end_date BETWEEN :from AND :to`, {
|
queryBuilder.andWhere(`season_period.start_date < :inputStartDate`, {
|
||||||
from: this.filterParam.start_date,
|
inputStartDate: this.filterParam.end_date,
|
||||||
to: this.filterParam.end_date,
|
});
|
||||||
|
|
||||||
|
queryBuilder.andWhere(`season_period.end_date > :inputEndDate`, {
|
||||||
|
inputEndDate: this.filterParam.start_date,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
queryBuilder.addOrderBy('season_period.priority', 'ASC');
|
||||||
|
|
||||||
return queryBuilder;
|
return queryBuilder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,12 @@ export class FilterItemDto extends BaseFilterDto implements FilterItemEntity {
|
||||||
})
|
})
|
||||||
item_categories: string[];
|
item_categories: string[];
|
||||||
|
|
||||||
|
@ApiProperty({ type: ['string'], required: false })
|
||||||
|
@Transform((body) => {
|
||||||
|
return Array.isArray(body.value) ? body.value : [body.value];
|
||||||
|
})
|
||||||
|
season_period_ids: string[];
|
||||||
|
|
||||||
@ApiProperty({ type: ['string'], required: false })
|
@ApiProperty({ type: ['string'], required: false })
|
||||||
@Transform((body) => {
|
@Transform((body) => {
|
||||||
return Array.isArray(body.value) ? body.value : [body.value];
|
return Array.isArray(body.value) ? body.value : [body.value];
|
||||||
|
|
Loading…
Reference in New Issue