92 lines
2.3 KiB
TypeScript
92 lines
2.3 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager';
|
|
import { ItemEntity } from '../../entities/item.entity';
|
|
import { SelectQueryBuilder } from 'typeorm';
|
|
import {
|
|
Param,
|
|
RelationParam,
|
|
} from 'src/core/modules/domain/entities/base-filter.entity';
|
|
|
|
@Injectable()
|
|
export class IndexItemManager extends BaseIndexManager<ItemEntity> {
|
|
async prepareData(): Promise<void> {
|
|
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: ['item_category', 'bundling_items'],
|
|
|
|
// relation yang hanya ingin dihitung (akan return number)
|
|
countRelations: [],
|
|
};
|
|
}
|
|
|
|
get selects(): string[] {
|
|
return [
|
|
`${this.tableName}.id`,
|
|
`${this.tableName}.created_at`,
|
|
`${this.tableName}.status`,
|
|
`${this.tableName}.item_type`,
|
|
`${this.tableName}.name`,
|
|
`${this.tableName}.hpp`,
|
|
`${this.tableName}.limit_type`,
|
|
`${this.tableName}.limit_value`,
|
|
`${this.tableName}.base_price`,
|
|
|
|
`item_category.id`,
|
|
`item_category.name`,
|
|
|
|
'bundling_items.id',
|
|
'bundling_items.name',
|
|
];
|
|
}
|
|
|
|
get specificFilter(): Param[] {
|
|
return [
|
|
{
|
|
cols: `${this.tableName}.name`,
|
|
data: this.filterParam.names,
|
|
},
|
|
{
|
|
cols: `${this.tableName}.item_type::text`,
|
|
data: this.filterParam.item_types,
|
|
},
|
|
{
|
|
cols: `${this.tableName}.limit_type::text`,
|
|
data: this.filterParam.limit_types,
|
|
},
|
|
{
|
|
cols: `item_category.name`,
|
|
data: this.filterParam.item_categories,
|
|
},
|
|
];
|
|
}
|
|
|
|
setQueryFilter(
|
|
queryBuilder: SelectQueryBuilder<ItemEntity>,
|
|
): SelectQueryBuilder<ItemEntity> {
|
|
if (this.filterParam.tenant_ids?.length) {
|
|
queryBuilder.andWhere(`${this.tableName}.tenant_id In (:...tenantIds)`, {
|
|
tenantIds: this.filterParam.tenant_ids,
|
|
});
|
|
} else if (!this.filterParam.all_item) {
|
|
queryBuilder.andWhere(`${this.tableName}.tenant_id Is Null`);
|
|
}
|
|
|
|
return queryBuilder;
|
|
}
|
|
}
|