mirror of
https://github.com/hexastack/hexabot
synced 2025-02-22 20:38:32 +00:00
fix: handover/handback lifecycle hook
This commit is contained in:
parent
1288eb87cf
commit
21301b9702
@ -80,26 +80,29 @@ export class SubscriberRepository extends BaseRepository<
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const subscriberUpdates: SubscriberUpdateDto = updates?.['$set'];
|
const subscriberUpdates: SubscriberUpdateDto = updates?.['$set'];
|
||||||
|
|
||||||
const oldSubscriber = await this.findOne(criteria);
|
if ('assignedTo' in subscriberUpdates) {
|
||||||
|
// In case of a handover or handback, emit events
|
||||||
|
const oldSubscriber = await this.findOne(criteria);
|
||||||
|
|
||||||
if (!oldSubscriber) {
|
if (!oldSubscriber) {
|
||||||
throw new Error('Something went wrong: subscriber does not exist');
|
throw new Error('Something went wrong: subscriber does not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subscriberUpdates.assignedTo !== oldSubscriber?.assignedTo) {
|
if (subscriberUpdates.assignedTo !== oldSubscriber?.assignedTo) {
|
||||||
this.eventEmitter.emit(
|
|
||||||
'hook:subscriber:assign',
|
|
||||||
subscriberUpdates,
|
|
||||||
oldSubscriber,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!(subscriberUpdates.assignedTo && oldSubscriber?.assignedTo)) {
|
|
||||||
this.eventEmitter.emit(
|
this.eventEmitter.emit(
|
||||||
'hook:analytics:passation',
|
'hook:subscriber:assign',
|
||||||
|
subscriberUpdates,
|
||||||
oldSubscriber,
|
oldSubscriber,
|
||||||
!!subscriberUpdates?.assignedTo,
|
|
||||||
);
|
);
|
||||||
subscriberUpdates.assignedAt = new Date();
|
|
||||||
|
if (!(subscriberUpdates.assignedTo && oldSubscriber?.assignedTo)) {
|
||||||
|
this.eventEmitter.emit(
|
||||||
|
'hook:analytics:passation',
|
||||||
|
oldSubscriber,
|
||||||
|
!!subscriberUpdates?.assignedTo,
|
||||||
|
);
|
||||||
|
subscriberUpdates.assignedAt = new Date();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user