* add migration guide and dto * add factory * add notifier * add repo * add services * coderabbit review --1 * coderabbit review --2 * coderabbit review --3 * further improvement * -- * fix * bookingWebhookFactory consideration and type fixes * cleanup * fix types * DI part1 * DI --part 2 * remove migrationGuide as we're WIP * using evyweb for DI -- 1 * DI --final * separate func instead of private class * adds a todo migration file * adjust structure * address feedback * remove todo_migrate * --1 * fix type * address feedback * add TODO comment * address requested changes --1 * address feedback --2 * restructure as per feedback * rename camelcase
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import type { WebhookEventDTO } from "../dto/types";
|
|
import type { ILogger } from "../interface/infrastructure";
|
|
import type { IWebhookNotifier, IWebhookNotificationHandler } from "../interface/webhook";
|
|
|
|
export class WebhookNotifier implements IWebhookNotifier {
|
|
private readonly log: ILogger;
|
|
|
|
constructor(private readonly handler: IWebhookNotificationHandler, logger: ILogger) {
|
|
this.log = logger.getSubLogger({ prefix: ["[WebhookNotifier]"] });
|
|
}
|
|
|
|
async emitWebhook(dto: WebhookEventDTO, isDryRun = false): Promise<void> {
|
|
const trigger = dto.triggerEvent;
|
|
|
|
try {
|
|
this.log.debug(`Emitting webhook event: ${trigger}`, {
|
|
bookingId: dto.bookingId,
|
|
eventTypeId: dto.eventTypeId,
|
|
isDryRun,
|
|
});
|
|
|
|
await this.handler.handleNotification(dto, isDryRun);
|
|
|
|
this.log.debug(`Successfully emitted webhook event: ${trigger}`, {
|
|
bookingId: dto.bookingId,
|
|
});
|
|
} catch (error) {
|
|
this.log.error(`Failed to emit webhook event: ${trigger}`, {
|
|
error: error instanceof Error ? error.message : String(error),
|
|
bookingId: dto.bookingId,
|
|
eventTypeId: dto.eventTypeId,
|
|
});
|
|
throw error;
|
|
}
|
|
}
|
|
}
|