pull/9078/head
Syed Ali Shahbaz 2022-05-26 12:12:13 +05:30 committed by GitHub
parent 92b011214c
commit 5e3b51c621
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 12 deletions

View File

@ -1,15 +1,16 @@
import { z } from "zod"; import { z } from "zod";
import { _WebhookModel as Webhook } from "@calcom/prisma/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 = [ export const WEBHOOK_TRIGGER_EVENTS = [
// WebhookTriggerEvents.BOOKING_CANCELLED, WebhookTriggerEvents.BOOKING_CANCELLED,
// WebhookTriggerEvents.BOOKING_CREATED, WebhookTriggerEvents.BOOKING_CREATED,
// WebhookTriggerEvents.BOOKING_RESCHEDULED, WebhookTriggerEvents.BOOKING_RESCHEDULED,
// ] as ["BOOKING_CANCELLED", "BOOKING_CREATED", "BOOKING_RESCHEDULED"]; ] as ["BOOKING_CANCELLED", "BOOKING_CREATED", "BOOKING_RESCHEDULED"];
const schemaWebhookBaseBodyParams = Webhook.pick({ const schemaWebhookBaseBodyParams = Webhook.pick({
id: true,
userId: true, userId: true,
eventTypeId: true, eventTypeId: true,
eventTriggers: true, eventTriggers: true,
@ -20,12 +21,13 @@ const schemaWebhookBaseBodyParams = Webhook.pick({
export const schemaWebhookCreateParams = z export const schemaWebhookCreateParams = z
.object({ .object({
id: z.string(),
subscriberUrl: z.string().url(), subscriberUrl: z.string().url(),
eventTriggers: z.any(), eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array(),
active: z.boolean(), active: z.boolean(),
// payloadTemplate: z.string().optional().nullable(), payloadTemplate: z.string().optional().nullable(),
// eventTypeId: z.number().optional(), eventTypeId: z.number().optional(),
// appId: z.string().optional().nullable(), appId: z.string().optional().nullable(),
}) })
.strict(); .strict();
@ -36,8 +38,7 @@ export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge(
export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams.merge( export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams.merge(
z.object({ z.object({
payloadTemplate: z.string().optional(), payloadTemplate: z.string().optional(),
/** @todo: don't use 'any' here and validate eventTriggers proper */ eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array().optional(),
eventTriggers: z.any().optional(),
subscriberUrl: z.string().optional(), subscriberUrl: z.string().optional(),
}) })
); );