-
Notifications
You must be signed in to change notification settings - Fork 593
/
Copy pathzapier-timer-stopped.handler.ts
31 lines (29 loc) · 1.21 KB
/
zapier-timer-stopped.handler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
import { Injectable } from '@nestjs/common';
import { TimerStoppedEvent } from '@gauzy/core';
import { ZapierWebhookService } from '../zapier-webhook.service';
@Injectable()
@EventsHandler(TimerStoppedEvent)
export class ZapierTimerStoppedHandler implements IEventHandler<TimerStoppedEvent> {
constructor(private readonly zapierWebhookService: ZapierWebhookService) {}
/**
* Handles the TimerStoppedEvent by notifying Zapier webhooks
*
* @param event - The TimerStoppedEvent that contains the time log details.
* @returns A Promise that resolves once the webhooks are notified
*/
async handle(event: TimerStoppedEvent): Promise<void> {
const timeLog = event.timeLog;
if (!timeLog.tenantId || !timeLog.organizationId) {
console.warn('Cannot process timer stopped event: missing tenantId or organizationId')
return;
}
await this.zapierWebhookService.notifyTimerStatusChanged({
event: 'timer.status.changed',
action: 'stop',
data: timeLog,
tenantId: timeLog.tenantId,
organizationId: timeLog.organizationId
});
}
}