feat(SPG-780): sync data session type
parent
8de744bc58
commit
1dae9ec356
|
@ -44,6 +44,12 @@ import { TransactionTaxModel } from 'src/modules/transaction/transaction/data/mo
|
||||||
import { TransactionItemModel } from 'src/modules/transaction/transaction/data/models/transaction-item.model';
|
import { TransactionItemModel } from 'src/modules/transaction/transaction/data/models/transaction-item.model';
|
||||||
import { VipCodeCreatedHandler } from './domain/managers/vip-code.handler';
|
import { VipCodeCreatedHandler } from './domain/managers/vip-code.handler';
|
||||||
import { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/item-rate.model';
|
import { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/item-rate.model';
|
||||||
|
import {
|
||||||
|
SeasonTypeDeletedHandler,
|
||||||
|
SeasonTypeUpdatedHandler,
|
||||||
|
} from './domain/managers/season-type.handler';
|
||||||
|
import { SeasonPeriodDataService } from 'src/modules/season-related/season-period/data/services/season-period-data.service';
|
||||||
|
import { SeasonPeriodModel } from 'src/modules/season-related/season-period/data/models/season-period.model';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -52,6 +58,7 @@ import { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/it
|
||||||
[
|
[
|
||||||
ItemModel,
|
ItemModel,
|
||||||
ItemRateModel,
|
ItemRateModel,
|
||||||
|
SeasonPeriodModel,
|
||||||
UserModel,
|
UserModel,
|
||||||
TransactionModel,
|
TransactionModel,
|
||||||
TransactionTaxModel,
|
TransactionTaxModel,
|
||||||
|
@ -82,6 +89,10 @@ import { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/it
|
||||||
UserUpdatedHandler,
|
UserUpdatedHandler,
|
||||||
UserPrivilegeUpdateHandler,
|
UserPrivilegeUpdateHandler,
|
||||||
|
|
||||||
|
SeasonTypeDeletedHandler,
|
||||||
|
SeasonTypeUpdatedHandler,
|
||||||
|
|
||||||
|
SeasonPeriodDataService,
|
||||||
TransactionDataService,
|
TransactionDataService,
|
||||||
UserDataService,
|
UserDataService,
|
||||||
ItemDataService,
|
ItemDataService,
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
|
||||||
|
import { CouchService } from '../../data/services/couch.service';
|
||||||
|
import { SeasonTypeDeletedEvent } from 'src/modules/season-related/season-type/domain/entities/event/season-type-deleted.event';
|
||||||
|
import { SeasonTypeChangeStatusEvent } from 'src/modules/season-related/season-type/domain/entities/event/season-type-change-status.event';
|
||||||
|
import { SeasonTypeUpdatedEvent } from 'src/modules/season-related/season-type/domain/entities/event/season-type-updated.event';
|
||||||
|
import { SeasonPeriodDataService } from 'src/modules/season-related/season-period/data/services/season-period-data.service';
|
||||||
|
|
||||||
|
@EventsHandler(SeasonTypeDeletedEvent)
|
||||||
|
export class SeasonTypeDeletedHandler
|
||||||
|
implements IEventHandler<SeasonTypeDeletedEvent>
|
||||||
|
{
|
||||||
|
constructor(private couchService: CouchService) {}
|
||||||
|
|
||||||
|
async handle(event: SeasonTypeDeletedEvent) {
|
||||||
|
console.log('deleted session type');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventsHandler(SeasonTypeChangeStatusEvent, SeasonTypeUpdatedEvent)
|
||||||
|
export class SeasonTypeUpdatedHandler
|
||||||
|
implements IEventHandler<SeasonTypeChangeStatusEvent>
|
||||||
|
{
|
||||||
|
constructor(
|
||||||
|
private couchService: CouchService,
|
||||||
|
private seasonPeriodService: SeasonPeriodDataService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async handle(event: SeasonTypeChangeStatusEvent) {
|
||||||
|
const data = event.data.data;
|
||||||
|
const typeID = data.id;
|
||||||
|
const periods = await this.seasonPeriodService.getManyByOptions({
|
||||||
|
where: {
|
||||||
|
season_type_id: typeID,
|
||||||
|
},
|
||||||
|
relations: ['season_type'],
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const period of periods) {
|
||||||
|
const dataID = period.id;
|
||||||
|
const couchData = await this.couchService.getDoc(dataID, 'season_period');
|
||||||
|
if (couchData) {
|
||||||
|
await this.couchService.updateDoc(
|
||||||
|
{
|
||||||
|
_id: dataID,
|
||||||
|
...period,
|
||||||
|
},
|
||||||
|
'season_period',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue