Files
calendar/packages/features/webhooks/lib/service/OOOWebhookService.ts
T
Syed Ali ShahbazandGitHub 110615b509 chore: add webhook architecture skeleton (#23247)
* 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
2025-09-12 20:02:50 +00:00

67 lines
1.7 KiB
TypeScript

import { WebhookTriggerEvents } from "@calcom/prisma/enums";
import type { OOOCreatedDTO } from "../dto/types";
import type { ITasker, ILogger } from "../interface/infrastructure";
import type { IWebhookRepository } from "../interface/services";
import type { IWebhookNotifier } from "../interface/webhook";
import { WebhookService } from "./WebhookService";
export class OOOWebhookService extends WebhookService {
constructor(
private readonly notifier: IWebhookNotifier,
repository: IWebhookRepository,
tasker: ITasker,
logger: ILogger
) {
super(repository, tasker, logger);
}
async emitOOOCreated(params: {
oooEntry: {
id: number;
start: string;
end: string;
createdAt: string;
updatedAt: string;
notes: string | null;
reason: {
emoji?: string;
reason?: string;
};
reasonId: number;
user: {
id: number;
name: string | null;
username: string | null;
timeZone: string;
email: string;
};
toUser: {
id: number;
name?: string | null;
username?: string | null;
email?: string;
timeZone?: string;
} | null;
uuid: string;
};
userId?: number | null;
teamId?: number | null;
orgId?: number | null;
platformClientId?: string;
isDryRun?: boolean;
}): Promise<void> {
const dto: OOOCreatedDTO = {
triggerEvent: WebhookTriggerEvents.OOO_CREATED,
createdAt: new Date().toISOString(),
userId: params.userId,
teamId: params.teamId,
orgId: params.orgId,
platformClientId: params.platformClientId,
oooEntry: params.oooEntry,
};
await this.notifier.emitWebhook(dto, params.isDryRun);
}
}