Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into development
commit
0172eea573
|
@ -3,4 +3,5 @@ export const DatabaseListen = [
|
||||||
'vip_code',
|
'vip_code',
|
||||||
'pos_activity',
|
'pos_activity',
|
||||||
'pos_cash_activity',
|
'pos_cash_activity',
|
||||||
|
'time_groups',
|
||||||
];
|
];
|
||||||
|
|
|
@ -52,6 +52,10 @@ import { SeasonPeriodDataService } from 'src/modules/season-related/season-perio
|
||||||
import { SeasonPeriodModel } from 'src/modules/season-related/season-period/data/models/season-period.model';
|
import { SeasonPeriodModel } from 'src/modules/season-related/season-period/data/models/season-period.model';
|
||||||
import { TransactionDemographyModel } from 'src/modules/transaction/transaction/data/models/transaction-demography.model';
|
import { TransactionDemographyModel } from 'src/modules/transaction/transaction/data/models/transaction-demography.model';
|
||||||
import { UserLoginModel } from 'src/modules/user-related/user/data/models/user-login.model';
|
import { UserLoginModel } from 'src/modules/user-related/user/data/models/user-login.model';
|
||||||
|
import {
|
||||||
|
TimeGroupDeletedHandler,
|
||||||
|
TimeGroupUpdatedHandler,
|
||||||
|
} from './domain/managers/time-group.handle';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -83,6 +87,10 @@ import { UserLoginModel } from 'src/modules/user-related/user/data/models/user-l
|
||||||
VipCodeCreatedHandler,
|
VipCodeCreatedHandler,
|
||||||
VipCategoryDeletedHandler,
|
VipCategoryDeletedHandler,
|
||||||
VipCategoryUpdatedHandler,
|
VipCategoryUpdatedHandler,
|
||||||
|
|
||||||
|
TimeGroupDeletedHandler,
|
||||||
|
TimeGroupUpdatedHandler,
|
||||||
|
|
||||||
SeasonPeriodDeletedHandler,
|
SeasonPeriodDeletedHandler,
|
||||||
SeasonPeriodUpdatedHandler,
|
SeasonPeriodUpdatedHandler,
|
||||||
ItemUpdatedHandler,
|
ItemUpdatedHandler,
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
|
||||||
|
import { CouchService } from '../../data/services/couch.service';
|
||||||
|
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { TimeGroupDeletedEvent } from 'src/modules/item-related/time-group/domain/entities/event/time-group-deleted.event';
|
||||||
|
import { TimeGroupChangeStatusEvent } from 'src/modules/item-related/time-group/domain/entities/event/time-group-change-status.event';
|
||||||
|
import { TimeGroupUpdatedEvent } from 'src/modules/item-related/time-group/domain/entities/event/time-group-updated.event';
|
||||||
|
|
||||||
|
@EventsHandler(TimeGroupDeletedEvent)
|
||||||
|
export class TimeGroupDeletedHandler
|
||||||
|
implements IEventHandler<TimeGroupDeletedEvent>
|
||||||
|
{
|
||||||
|
constructor(private couchService: CouchService) {}
|
||||||
|
|
||||||
|
async handle(event: TimeGroupDeletedEvent) {
|
||||||
|
const data = await this.couchService.deleteDoc(
|
||||||
|
{
|
||||||
|
_id: event.data.id,
|
||||||
|
...event.data.data,
|
||||||
|
},
|
||||||
|
'time_groups',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventsHandler(TimeGroupChangeStatusEvent, TimeGroupUpdatedEvent)
|
||||||
|
export class TimeGroupUpdatedHandler
|
||||||
|
implements IEventHandler<TimeGroupChangeStatusEvent>
|
||||||
|
{
|
||||||
|
constructor(private couchService: CouchService) {}
|
||||||
|
|
||||||
|
async handle(event: TimeGroupChangeStatusEvent) {
|
||||||
|
const dataOld = event.data.old;
|
||||||
|
const data = event.data.data;
|
||||||
|
|
||||||
|
// change status to active
|
||||||
|
if (dataOld?.status != data.status && data.status == STATUS.ACTIVE) {
|
||||||
|
await this.couchService.createDoc(
|
||||||
|
{
|
||||||
|
_id: data.id,
|
||||||
|
...data,
|
||||||
|
},
|
||||||
|
'time_groups',
|
||||||
|
);
|
||||||
|
} else if (dataOld?.status != data.status) {
|
||||||
|
await this.couchService.deleteDoc(
|
||||||
|
{
|
||||||
|
_id: data.id,
|
||||||
|
...data,
|
||||||
|
},
|
||||||
|
'time_groups',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// update
|
||||||
|
else {
|
||||||
|
await this.couchService.updateDoc(
|
||||||
|
{
|
||||||
|
_id: data.id,
|
||||||
|
...data,
|
||||||
|
},
|
||||||
|
'time_groups',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue