From 35ba69fb8ae042aaef4f5d8eb61f0dc7cfe1ff8f Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:12:13 +0530 Subject: [PATCH] added ID --- lib/validations/webhook.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index 44f433b3c1..f523c4c71e 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -1,15 +1,16 @@ import { z } from "zod"; import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; -// import { WebhookTriggerEvents } from "@calcom/prisma/client"; +import { WebhookTriggerEvents } from "@calcom/prisma/client"; -// export const WEBHOOK_TRIGGER_EVENTS = [ -// WebhookTriggerEvents.BOOKING_CANCELLED, -// WebhookTriggerEvents.BOOKING_CREATED, -// WebhookTriggerEvents.BOOKING_RESCHEDULED, -// ] as ["BOOKING_CANCELLED", "BOOKING_CREATED", "BOOKING_RESCHEDULED"]; +export const WEBHOOK_TRIGGER_EVENTS = [ + WebhookTriggerEvents.BOOKING_CANCELLED, + WebhookTriggerEvents.BOOKING_CREATED, + WebhookTriggerEvents.BOOKING_RESCHEDULED, +] as ["BOOKING_CANCELLED", "BOOKING_CREATED", "BOOKING_RESCHEDULED"]; const schemaWebhookBaseBodyParams = Webhook.pick({ + id: true, userId: true, eventTypeId: true, eventTriggers: true, @@ -20,12 +21,13 @@ const schemaWebhookBaseBodyParams = Webhook.pick({ export const schemaWebhookCreateParams = z .object({ + id: z.string(), subscriberUrl: z.string().url(), - eventTriggers: z.any(), + eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array(), active: z.boolean(), -// payloadTemplate: z.string().optional().nullable(), -// eventTypeId: z.number().optional(), -// appId: z.string().optional().nullable(), + payloadTemplate: z.string().optional().nullable(), + eventTypeId: z.number().optional(), + appId: z.string().optional().nullable(), }) .strict(); @@ -36,8 +38,7 @@ export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge( export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams.merge( z.object({ payloadTemplate: z.string().optional(), - /** @todo: don't use 'any' here and validate eventTriggers proper */ - eventTriggers: z.any().optional(), + eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array().optional(), subscriberUrl: z.string().optional(), }) );