95 lines
2.5 KiB
TypeScript
95 lines
2.5 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager';
|
|
import { SelectQueryBuilder } from 'typeorm';
|
|
import {
|
|
Param,
|
|
RelationParam,
|
|
} from 'src/core/modules/domain/entities/base-filter.entity';
|
|
import { ItemRateEntity } from 'src/modules/item-related/item-rate/domain/entities/item-rate.entity';
|
|
|
|
@Injectable()
|
|
export class IndexItemRatesManager extends BaseIndexManager<ItemRateEntity> {
|
|
async prepareData(): Promise<void> {
|
|
this.filterParam.order_by = `season_period.id`;
|
|
return;
|
|
}
|
|
|
|
async beforeProcess(): Promise<void> {
|
|
return;
|
|
}
|
|
|
|
async afterProcess(): Promise<void> {
|
|
return;
|
|
}
|
|
|
|
get relations(): RelationParam {
|
|
return {
|
|
// relation only join (for query purpose)
|
|
joinRelations: [],
|
|
|
|
// relation join and select (relasi yang ingin ditampilkan),
|
|
selectRelations: ['season_period', 'season_period.season_type'],
|
|
|
|
// relation yang hanya ingin dihitung (akan return number)
|
|
countRelations: [],
|
|
};
|
|
}
|
|
|
|
get selects(): string[] {
|
|
return [
|
|
`${this.tableName}.id`,
|
|
`${this.tableName}.item_id`,
|
|
`${this.tableName}.price`,
|
|
|
|
`season_period.id`,
|
|
`season_period.priority`,
|
|
`season_period.created_at`,
|
|
`season_period.creator_name`,
|
|
`season_period.editor_name`,
|
|
`season_period.updated_at`,
|
|
`season_period.status`,
|
|
`season_period.start_date`,
|
|
`season_period.end_date`,
|
|
`season_period.days`,
|
|
`season_period.holiday_name`,
|
|
|
|
'season_type.id',
|
|
'season_type.name',
|
|
];
|
|
}
|
|
|
|
get specificFilter(): Param[] {
|
|
return [];
|
|
}
|
|
|
|
setQueryFilter(
|
|
queryBuilder: SelectQueryBuilder<ItemRateEntity>,
|
|
): SelectQueryBuilder<ItemRateEntity> {
|
|
if (this.filterParam.item_ids) {
|
|
queryBuilder.andWhere(`${this.tableName}.item_id In (:...itemIds)`, {
|
|
itemIds: this.filterParam.item_ids,
|
|
});
|
|
}
|
|
|
|
if (this.filterParam.season_period_ids) {
|
|
queryBuilder.andWhere(`season_period.id In (:...itemIds)`, {
|
|
itemIds: this.filterParam.season_period_ids,
|
|
});
|
|
}
|
|
|
|
if (this.filterParam.start_date) {
|
|
queryBuilder.andWhere(`season_period.start_date < :inputStartDate`, {
|
|
inputStartDate: this.filterParam.end_date,
|
|
});
|
|
|
|
queryBuilder.andWhere(`season_period.end_date > :inputEndDate`, {
|
|
inputEndDate: this.filterParam.start_date,
|
|
});
|
|
}
|
|
|
|
queryBuilder.addOrderBy('season_period.priority', 'ASC');
|
|
|
|
return queryBuilder;
|
|
}
|
|
}
|