fix(SPG-640) Sync harga ketika ditambahkan melalui item rate (case item sudah dibuat)
parent
20848aab3c
commit
2fc80c7cfc
|
@ -17,6 +17,8 @@ import {
|
||||||
} from './domain/managers/season-period.handler';
|
} from './domain/managers/season-period.handler';
|
||||||
import {
|
import {
|
||||||
ItemDeletedHandler,
|
ItemDeletedHandler,
|
||||||
|
ItemPriceUpdatedHandler,
|
||||||
|
ItemRateUpdatedHandler,
|
||||||
ItemUpdatedHandler,
|
ItemUpdatedHandler,
|
||||||
} from './domain/managers/item.handler';
|
} from './domain/managers/item.handler';
|
||||||
import {
|
import {
|
||||||
|
@ -68,6 +70,8 @@ import { VipCodeCreatedHandler } from './domain/managers/vip-code.handler';
|
||||||
SeasonPeriodUpdatedHandler,
|
SeasonPeriodUpdatedHandler,
|
||||||
ItemUpdatedHandler,
|
ItemUpdatedHandler,
|
||||||
ItemDeletedHandler,
|
ItemDeletedHandler,
|
||||||
|
ItemRateUpdatedHandler,
|
||||||
|
ItemPriceUpdatedHandler,
|
||||||
UserDeletedHandler,
|
UserDeletedHandler,
|
||||||
UserUpdatedHandler,
|
UserUpdatedHandler,
|
||||||
UserPrivilegeUpdateHandler,
|
UserPrivilegeUpdateHandler,
|
||||||
|
|
|
@ -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 { 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 { 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 { 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)
|
@EventsHandler(ItemDeletedEvent)
|
||||||
export class ItemDeletedHandler implements IEventHandler<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',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue