Compare commits
No commits in common. "0512c51f8e3d9cc1510f240d44701c041e1a728c" and "033ed0046e61b8503f7e0aec6ee04e4a8f690ddf" have entirely different histories.
0512c51f8e
...
033ed0046e
|
@ -3,5 +3,4 @@ export const DatabaseListen = [
|
||||||
'vip_code',
|
'vip_code',
|
||||||
'pos_activity',
|
'pos_activity',
|
||||||
'pos_cash_activity',
|
'pos_cash_activity',
|
||||||
'time_groups',
|
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,65 +0,0 @@
|
||||||
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