fix(SPG-640) Sync harga ketika ditambahkan melalui item rate (case item sudah dibuat)

pull/37/head
Aswin Ashar Abdullah 2024-07-23 18:25:57 +07:00
parent 20848aab3c
commit 2fc80c7cfc
2 changed files with 89 additions and 0 deletions

View File

@ -17,6 +17,8 @@ import {
} from './domain/managers/season-period.handler';
import {
ItemDeletedHandler,
ItemPriceUpdatedHandler,
ItemRateUpdatedHandler,
ItemUpdatedHandler,
} from './domain/managers/item.handler';
import {
@ -68,6 +70,8 @@ import { VipCodeCreatedHandler } from './domain/managers/vip-code.handler';
SeasonPeriodUpdatedHandler,
ItemUpdatedHandler,
ItemDeletedHandler,
ItemRateUpdatedHandler,
ItemPriceUpdatedHandler,
UserDeletedHandler,
UserUpdatedHandler,
UserPrivilegeUpdateHandler,

View File

@ -5,6 +5,9 @@ import { ItemDeletedEvent } from 'src/modules/item-related/item/domain/entities/
import { ItemUpdatedEvent } from 'src/modules/item-related/item/domain/entities/event/item-updated.event';
import { ItemChangeStatusEvent } from 'src/modules/item-related/item/domain/entities/event/item-change-status.event';
import { ItemDataService } from 'src/modules/item-related/item/data/services/item-data.service';
import { SeasonPeriodUpdatedEvent } from 'src/modules/season-related/season-period/domain/entities/event/season-period-updated.event';
import { SeasonPeriodChangeStatusEvent } from 'src/modules/season-related/season-period/domain/entities/event/season-period-change-status.event';
import { ItemRateUpdatedEvent } from 'src/modules/item-related/item-rate/domain/entities/event/item-rate-updated.event';
@EventsHandler(ItemDeletedEvent)
export class ItemDeletedHandler implements IEventHandler<ItemDeletedEvent> {
@ -79,3 +82,85 @@ export class ItemUpdatedHandler
}
}
}
@EventsHandler(SeasonPeriodChangeStatusEvent, SeasonPeriodUpdatedEvent)
export class ItemPriceUpdatedHandler
implements IEventHandler<SeasonPeriodChangeStatusEvent>
{
constructor(
private couchService: CouchService,
private itemService: ItemDataService,
) {}
async handle(event: SeasonPeriodChangeStatusEvent) {
const data = event.data.data;
// change status to active
if (data.status == STATUS.ACTIVE) {
const dataItems = await this.itemService.getManyByOptions({
where: {
status: STATUS.ACTIVE,
},
relations: [
'item_category',
'bundling_items',
'bundling_items.item_category',
'item_rates',
'item_rates.item',
'item_rates.season_period',
'item_rates.season_period.season_type',
],
});
for (const dataItem of dataItems) {
await this.couchService.updateDoc(
{
_id: dataItem.id,
...dataItem,
},
'item',
);
}
}
}
}
@EventsHandler(ItemRateUpdatedEvent)
export class ItemRateUpdatedHandler
implements IEventHandler<ItemRateUpdatedEvent>
{
constructor(
private couchService: CouchService,
private itemService: ItemDataService,
) {}
async handle(event: ItemRateUpdatedEvent) {
const data = event.data.data;
const dataItems = await this.itemService.getManyByOptions({
where: {
status: STATUS.ACTIVE,
id: data.item?.id,
},
relations: [
'item_category',
'bundling_items',
'bundling_items.item_category',
'item_rates',
'item_rates.item',
'item_rates.season_period',
'item_rates.season_period.season_type',
],
});
for (const dataItem of dataItems) {
await this.couchService.updateDoc(
{
_id: dataItem.id,
...dataItem,
},
'item',
);
}
}
}