Compare commits
No commits in common. "737575176e3e2ffcdc5f50f00186a5bec96c991b" and "ab9db39a5f69153f174433945b4feff7c76c50e1" have entirely different histories.
737575176e
...
ab9db39a5f
|
@ -1,66 +0,0 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity';
|
||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
||||
import { IndexItemManager } from 'src/modules/item-related/item/domain/usecases/managers/index-item.manager';
|
||||
import { SelectQueryBuilder } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class BookingItemManager extends IndexItemManager {
|
||||
get relations(): RelationParam {
|
||||
return {
|
||||
// relation only join (for query purpose)
|
||||
joinRelations: [],
|
||||
|
||||
// relation join and select (relasi yang ingin ditampilkan),
|
||||
selectRelations: [
|
||||
'item_category',
|
||||
'bundling_items',
|
||||
'tenant',
|
||||
'time_group',
|
||||
'item_rates',
|
||||
],
|
||||
|
||||
// relation yang hanya ingin dihitung (akan return number)
|
||||
countRelations: [],
|
||||
};
|
||||
}
|
||||
|
||||
get selects(): string[] {
|
||||
const parent = super.selects;
|
||||
return [
|
||||
...parent,
|
||||
'item_rates.id',
|
||||
'item_rates.price',
|
||||
'item_rates.season_period_id',
|
||||
];
|
||||
}
|
||||
|
||||
getResult(): PaginationResponse<ItemEntity> {
|
||||
const result = super.getResult();
|
||||
const { data, total } = result;
|
||||
const hasRates = (this.filterParam.season_period_ids?.length ?? 0) > 0;
|
||||
const items = data.map((item) => {
|
||||
const { item_rates, ...rest } = item;
|
||||
const rate = item_rates?.[0]?.['price'] ?? rest.base_price;
|
||||
return {
|
||||
...rest,
|
||||
base_price: hasRates ? rate : rest.base_price,
|
||||
};
|
||||
});
|
||||
return { total, data: items };
|
||||
}
|
||||
|
||||
setQueryFilter(
|
||||
queryBuilder: SelectQueryBuilder<ItemEntity>,
|
||||
): SelectQueryBuilder<ItemEntity> {
|
||||
const query = super.setQueryFilter(queryBuilder);
|
||||
|
||||
if (this.filterParam.season_period_ids) {
|
||||
query.andWhere(`item_rates.season_period_id In (:...seasonIds)`, {
|
||||
seasonIds: this.filterParam.season_period_ids,
|
||||
});
|
||||
}
|
||||
return query;
|
||||
}
|
||||
}
|
|
@ -5,15 +5,15 @@ import { PaginationResponse } from 'src/core/response/domain/ok-response.interfa
|
|||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { ItemReadService } from 'src/modules/item-related/item/data/services/item-read.service';
|
||||
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
||||
import { IndexItemManager } from 'src/modules/item-related/item/domain/usecases/managers/index-item.manager';
|
||||
import { FilterItemDto } from 'src/modules/item-related/item/infrastructure/dto/filter-item.dto';
|
||||
import { BookingItemManager } from '../domain/usecases/managers/booking-item.manager';
|
||||
|
||||
@ApiTags('Booking Item')
|
||||
@Controller('v1/booking-item')
|
||||
@Public(true)
|
||||
export class ItemController {
|
||||
constructor(
|
||||
private indexManager: BookingItemManager,
|
||||
private indexManager: IndexItemManager,
|
||||
private serviceData: ItemReadService,
|
||||
) {}
|
||||
|
||||
|
|
|
@ -131,17 +131,11 @@ export class BookingOrderController {
|
|||
@Get(':id')
|
||||
async get(@Param('id') transactionId: string) {
|
||||
const data = await this.serviceData.getOneByOptions({
|
||||
relations: [
|
||||
'items',
|
||||
'parent_transaction',
|
||||
'items.item',
|
||||
'items.item.time_group',
|
||||
],
|
||||
relations: ['items', 'items.item', 'items.item.time_group'],
|
||||
where: { id: transactionId },
|
||||
});
|
||||
|
||||
const {
|
||||
parent_id,
|
||||
customer_name,
|
||||
customer_phone,
|
||||
booking_date,
|
||||
|
@ -149,7 +143,6 @@ export class BookingOrderController {
|
|||
status,
|
||||
id,
|
||||
items,
|
||||
parent_transaction,
|
||||
} = data;
|
||||
|
||||
let timeGroup = null;
|
||||
|
@ -202,20 +195,6 @@ export class BookingOrderController {
|
|||
maskedCustomerPhone = '*'.repeat(customer_phone.length - 4) + last4;
|
||||
}
|
||||
|
||||
let parentTransaction = undefined;
|
||||
if (parent_transaction) {
|
||||
const {
|
||||
id: parentId,
|
||||
invoice_code: parentInvoiceCode,
|
||||
invoice_date: parentInvoiceDate,
|
||||
} = parent_transaction;
|
||||
parentTransaction = {
|
||||
id: parentId,
|
||||
invoice_code: parentInvoiceCode,
|
||||
invoice_date: parentInvoiceDate,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
customer_name,
|
||||
customer_phone: maskedCustomerPhone,
|
||||
|
@ -223,10 +202,8 @@ export class BookingOrderController {
|
|||
invoice_code,
|
||||
status,
|
||||
id,
|
||||
is_reschedule: !!parent_id,
|
||||
items: usageItems,
|
||||
time_group: timeGroup,
|
||||
parent: parentTransaction,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ import { CqrsModule } from '@nestjs/cqrs';
|
|||
import { RescheduleVerificationModel } from './data/models/reschedule-verification.model';
|
||||
import { RescheduleVerificationManager } from './domain/usecases/managers/reschedule-verification.manager';
|
||||
import { RescheduleManager } from './domain/usecases/managers/reschedule.manager';
|
||||
import { BookingItemManager } from './domain/usecases/managers/booking-item.manager';
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
|
@ -32,7 +31,6 @@ import { BookingItemManager } from './domain/usecases/managers/booking-item.mana
|
|||
CreateBookingManager,
|
||||
RescheduleVerificationManager,
|
||||
RescheduleManager,
|
||||
BookingItemManager,
|
||||
],
|
||||
})
|
||||
export class BookingOrderModule {}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.entity';
|
||||
import { ItemType } from 'src/modules/item-related/item-category/constants';
|
||||
import { LimitType } from '../../constants';
|
||||
import { ItemRateEntity } from 'src/modules/item-related/item-rate/domain/entities/item-rate.entity';
|
||||
|
||||
export interface ItemEntity extends BaseStatusEntity {
|
||||
name: string;
|
||||
|
@ -20,6 +19,4 @@ export interface ItemEntity extends BaseStatusEntity {
|
|||
show_to_booking: boolean;
|
||||
breakdown_bundling?: boolean;
|
||||
booking_description?: string;
|
||||
|
||||
item_rates?: ItemRateEntity[] | any[];
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ export class IndexItemManager extends BaseIndexManager<ItemEntity> {
|
|||
|
||||
if (this.filterParam.time_group_ids?.length) {
|
||||
queryBuilder.andWhere(
|
||||
`(${this.tableName}.time_group_id In (:...timeGroupIds) OR ${this.tableName}.time_group_id Is Null)`,
|
||||
`${this.tableName}.time_group_id In (:...timeGroupIds) OR ${this.tableName}.time_group_id Is Null`,
|
||||
{
|
||||
timeGroupIds: this.filterParam.time_group_ids,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue