fix(SPG-552) BE - Update Item Rate pada module season period
continuous-integration/drone/tag Build is passing
Details
continuous-integration/drone/tag Build is passing
Details
parent
cc7a345fff
commit
0368f3452b
|
@ -1,4 +1,4 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
|
@ -17,6 +17,7 @@ import { DetailItemRateManager } from './domain/usecases/managers/detail-item-ra
|
|||
import { BatchDeleteItemRateManager } from './domain/usecases/managers/batch-delete-item-rate.manager';
|
||||
import { ItemRateModel } from './data/models/item-rate.model';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
|
@ -38,5 +39,9 @@ import { ItemRateModel } from './data/models/item-rate.model';
|
|||
ItemRateDataOrchestrator,
|
||||
ItemRateReadOrchestrator,
|
||||
],
|
||||
exports: [
|
||||
ItemRateDataService,
|
||||
ItemRateReadService,
|
||||
]
|
||||
})
|
||||
export class ItemRateModule {}
|
||||
export class ItemRateModule { }
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
import { IEvent } from 'src/core/strings/constants/interface.constants';
|
||||
|
||||
export class SeasonPeriodPriceUpdatedEvent {
|
||||
constructor(public readonly data: IEvent) { }
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
import { EventsHandler, IEventHandler } from "@nestjs/cqrs";
|
||||
import { SeasonPeriodPriceUpdatedEvent } from "../../entities/event/season-period-price-updated.event";
|
||||
import { SeasonPeriodReadService } from "../../../data/services/season-period-read.service";
|
||||
import { SeasonPeriodDataService } from "../../../data/services/season-period-data.service";
|
||||
import { SeasonPeriodModel } from "../../../data/models/season-period.model";
|
||||
import { ItemRateDataService } from "src/modules/item-related/item-rate/data/services/item-rate-data.service";
|
||||
import { ItemRateModel } from "src/modules/item-related/item-rate/data/models/item-rate.model";
|
||||
import { IsNull } from "typeorm";
|
||||
|
||||
@EventsHandler(SeasonPeriodPriceUpdatedEvent)
|
||||
export class SeasonPeriodPriceUpdatedHandler implements IEventHandler<SeasonPeriodPriceUpdatedEvent> {
|
||||
|
||||
constructor(
|
||||
private readService: SeasonPeriodReadService,
|
||||
private dataService: SeasonPeriodDataService,
|
||||
private rateDataService: ItemRateDataService,
|
||||
) { }
|
||||
|
||||
async handle(event: SeasonPeriodPriceUpdatedEvent) {
|
||||
const datas = await this.readService.getManyByOptions({
|
||||
where: {
|
||||
season_type_id: event.data.data.season_period?.id
|
||||
}
|
||||
}).then(data => {
|
||||
return data.map(item => {
|
||||
return {
|
||||
...item,
|
||||
item_rates: event.data.data.item_rates,
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const queryRunner = this.dataService
|
||||
.getRepository()
|
||||
.manager.connection.createQueryRunner();
|
||||
|
||||
await this.dataService.createBatch(
|
||||
queryRunner,
|
||||
SeasonPeriodModel,
|
||||
datas
|
||||
)
|
||||
|
||||
await this.deleteUnusedItem()
|
||||
}
|
||||
|
||||
async deleteUnusedItem() {
|
||||
const queryRunnerItem = this.rateDataService
|
||||
.getRepository()
|
||||
.manager.connection.createQueryRunner();
|
||||
|
||||
await this.rateDataService.deleteByOptions(
|
||||
queryRunnerItem,
|
||||
ItemRateModel,
|
||||
{
|
||||
where: {
|
||||
season_period_id: IsNull()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
import { Injectable } from "@nestjs/common";
|
||||
import { BaseCustomManager } from "src/core/modules/domain/usecase/managers/base-custom.manager";
|
||||
import { SeasonPeriodEntity } from "../../entities/season-period.entity";
|
||||
import { EventTopics } from "src/core/strings/constants/interface.constants";
|
||||
import { SeasonPeriodModel } from "../../../data/models/season-period.model";
|
||||
import { SeasonPeriodPriceUpdatedHandler } from "../handlers/season-period-price-updated.handler";
|
||||
import { SeasonPeriodPriceUpdatedEvent } from "../../entities/event/season-period-price-updated.event";
|
||||
import { OPERATION } from "src/core/strings/constants/base.constants";
|
||||
|
||||
@Injectable()
|
||||
export class UpdateSeasonPeriodPriceManager extends BaseCustomManager<SeasonPeriodEntity> {
|
||||
|
||||
async validateProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async process(): Promise<void> {
|
||||
// this.publishEvents();
|
||||
|
||||
this.eventBus.publish(
|
||||
new SeasonPeriodPriceUpdatedEvent({
|
||||
id: '',
|
||||
old: null,
|
||||
data: this.data,
|
||||
user: this.user,
|
||||
description: '',
|
||||
module: this.tableName,
|
||||
op: OPERATION.CREATE,
|
||||
})
|
||||
)
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return SeasonPeriodModel;;
|
||||
}
|
||||
|
||||
getResult() {
|
||||
return;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
// {
|
||||
// topic: SeasonPeriodPriceUpdatedEvent,
|
||||
// data: this.data,
|
||||
// }
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -15,6 +15,7 @@ import { BatchInactiveSeasonPeriodManager } from './managers/batch-inactive-seas
|
|||
import { BatchActiveSeasonPeriodManager } from './managers/batch-active-season-period.manager';
|
||||
import { BatchDeleteSeasonPeriodManager } from './managers/batch-delete-season-period.manager';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { UpdateSeasonPeriodPriceManager } from './managers/update-season-period-price.manager';
|
||||
|
||||
@Injectable()
|
||||
export class SeasonPeriodDataOrchestrator extends BaseDataTransactionOrchestrator<SeasonPeriodEntity> {
|
||||
|
@ -29,6 +30,7 @@ export class SeasonPeriodDataOrchestrator extends BaseDataTransactionOrchestrato
|
|||
private batchActiveManager: BatchActiveSeasonPeriodManager,
|
||||
private batchConfirmManager: BatchConfirmSeasonPeriodManager,
|
||||
private batchInactiveManager: BatchInactiveSeasonPeriodManager,
|
||||
private updatePriceManager: UpdateSeasonPeriodPriceManager,
|
||||
private serviceData: SeasonPeriodDataService,
|
||||
) {
|
||||
super();
|
||||
|
@ -48,6 +50,13 @@ export class SeasonPeriodDataOrchestrator extends BaseDataTransactionOrchestrato
|
|||
return this.updateManager.getResult();
|
||||
}
|
||||
|
||||
async updatePrice(data): Promise<any> {
|
||||
this.updatePriceManager.setData(data);
|
||||
this.updatePriceManager.setService(this.serviceData, TABLE_NAME.SEASON_PERIOD);
|
||||
await this.updatePriceManager.execute();
|
||||
return this.updatePriceManager.getResult();
|
||||
}
|
||||
|
||||
async delete(dataId): Promise<String> {
|
||||
this.deleteManager.setData(dataId);
|
||||
this.deleteManager.setService(this.serviceData, TABLE_NAME.SEASON_PERIOD);
|
||||
|
|
|
@ -5,13 +5,11 @@ import { ApiProperty } from '@nestjs/swagger';
|
|||
import { IsObject, ValidateIf } from 'class-validator';
|
||||
import { SeasonTypeModel } from 'src/modules/season-related/season-type/data/models/season-type.model';
|
||||
import { Exclude } from 'class-transformer';
|
||||
import { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/item-rate.model';
|
||||
import { SeasonPeriodHolidayDto } from './season-period-holiday.dto';
|
||||
|
||||
export class UpdateSeasonPeriodDto
|
||||
extends BaseStatusDto
|
||||
implements SeasonPeriodEntity
|
||||
{
|
||||
implements SeasonPeriodEntity {
|
||||
@ApiProperty({
|
||||
type: Object,
|
||||
required: true,
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsObject } from "class-validator";
|
||||
import { ItemRateModel } from "src/modules/item-related/item-rate/data/models/item-rate.model";
|
||||
import { SeasonTypeModel } from "src/modules/season-related/season-type/data/models/season-type.model";
|
||||
|
||||
export class UpdateSeasonPriceDto {
|
||||
@ApiProperty({
|
||||
type: Object,
|
||||
required: true,
|
||||
example: {
|
||||
id: 'uuid',
|
||||
name: 'High Season',
|
||||
},
|
||||
})
|
||||
@IsObject()
|
||||
season_period: SeasonTypeModel;
|
||||
|
||||
@ApiProperty({
|
||||
type: [Object],
|
||||
example: [
|
||||
{
|
||||
item: {
|
||||
id: 'uuid',
|
||||
name: 'Entrance Ticket',
|
||||
},
|
||||
price: 10000,
|
||||
},
|
||||
],
|
||||
})
|
||||
item_rates: ItemRateModel[];
|
||||
}
|
|
@ -18,6 +18,7 @@ import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto'
|
|||
import { Public } from 'src/core/guards';
|
||||
import { UpdateSeasonPeriodDto } from './dto/update-season-period.dto';
|
||||
import { UpdateSeasonPeriodItemDto } from './dto/update-season-period-item.dto';
|
||||
import { UpdateSeasonPriceDto } from './dto/update-season-price.dto';
|
||||
|
||||
@ApiTags(`${ MODULE_NAME.SEASON_PERIOD.split('-').join(' ') } - data`)
|
||||
@Controller(MODULE_NAME.SEASON_PERIOD)
|
||||
|
@ -31,6 +32,12 @@ export class SeasonPeriodDataController {
|
|||
return await this.orchestrator.create(data);
|
||||
}
|
||||
|
||||
@Post('/update-price')
|
||||
async updatePrice(@Body() body: UpdateSeasonPriceDto): Promise<BatchResult> {
|
||||
console.log('here')
|
||||
return await this.orchestrator.updatePrice(body);
|
||||
}
|
||||
|
||||
@Put('/batch-delete')
|
||||
async batchDeleted(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||
return await this.orchestrator.batchDelete(body.ids);
|
||||
|
|
|
@ -26,6 +26,8 @@ import { SeasonPeriodHolidayHandler } from './domain/usecases/handlers/season-pe
|
|||
import { IndexSeasonPeriodeItemManager } from './domain/usecases/managers/index-season-period-item.manager';
|
||||
import { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/item-rate.model';
|
||||
import { ItemRateReadService } from 'src/modules/item-related/item-rate/data/services/item-rate-read.service';
|
||||
import { SeasonPeriodPriceUpdatedHandler } from './domain/usecases/handlers/season-period-price-updated.handler';
|
||||
import { UpdateSeasonPeriodPriceManager } from './domain/usecases/managers/update-season-period-price.manager';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -36,6 +38,7 @@ import { ItemRateReadService } from 'src/modules/item-related/item-rate/data/ser
|
|||
controllers: [SeasonPeriodDataController, SeasonPeriodReadController],
|
||||
providers: [
|
||||
SeasonPeriodHolidayHandler,
|
||||
SeasonPeriodPriceUpdatedHandler,
|
||||
|
||||
IndexSeasonPeriodManager,
|
||||
IndexSeasonPeriodeItemManager,
|
||||
|
@ -43,6 +46,7 @@ import { ItemRateReadService } from 'src/modules/item-related/item-rate/data/ser
|
|||
CreateSeasonPeriodManager,
|
||||
DeleteSeasonPeriodManager,
|
||||
UpdateSeasonPeriodManager,
|
||||
UpdateSeasonPeriodPriceManager,
|
||||
ActiveSeasonPeriodManager,
|
||||
ConfirmSeasonPeriodManager,
|
||||
InactiveSeasonPeriodManager,
|
||||
|
|
Loading…
Reference in New Issue