From d569296654495621b0475a4636fa9ac937cccd56 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 9 Jun 2022 17:09:20 +0530 Subject: [PATCH 01/19] Add webhook trigger --init --- pages/api/bookings/index.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index 40f24283ee..1951e4475d 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -81,7 +81,31 @@ async function createOrlistAllBookings( const data = await prisma.booking.create({ data: { ...safe.data } }); const booking = schemaBookingReadPublic.parse(data); - if (booking) res.status(201).json({ booking, message: "Booking created successfully" }); + if (booking) { + res.status(201).json({ booking, message: "Booking created successfully" }); + + // Send Webhook call if hooked to BOOKING_CREATED & BOOKING_RESCHEDULED +// const eventTrigger: WebhookTriggerEvents = rescheduleUid ? "BOOKING_RESCHEDULED" : "BOOKING_CREATED"; +// const subscriberOptions = { +// userId: user.id, +// eventTypeId, +// triggerEvent: eventTrigger, +// }; + +// const subscribers = await getSubscribers(subscriberOptions); +// const bookingId = booking?.id; +// const promises = subscribers.map((sub) => +// sendPayload(eventTrigger, new Date().toISOString(), sub, { +// ...evt, +// bookingId, +// rescheduleUid, +// metadata: reqBody.metadata, +// }).catch((e) => { +// console.error(`Error executing webhook for event: ${eventTrigger}, URL: ${sub.subscriberUrl}`, e); +// }) +// ); +// await Promise.all(promises); + } else (error: Error) => { console.log(error); From cd482cd91a44a4631bb0be0bce4b82968c4c5068 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Fri, 10 Jun 2022 11:40:38 +0530 Subject: [PATCH 02/19] Add getWebhook function --- lib/utils/webhookSubscriptions.ts | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lib/utils/webhookSubscriptions.ts diff --git a/lib/utils/webhookSubscriptions.ts b/lib/utils/webhookSubscriptions.ts new file mode 100644 index 0000000000..bdf9d95576 --- /dev/null +++ b/lib/utils/webhookSubscriptions.ts @@ -0,0 +1,42 @@ +import { WebhookTriggerEvents } from "@prisma/client"; + +import prisma from "@calcom/prisma"; + +export type GetSubscriberOptions = { + userId: number; + eventTypeId: number; + triggerEvent: WebhookTriggerEvents; +}; + +const getWebhooks = async (options: GetSubscriberOptions) => { + const { userId, eventTypeId } = options; + const allWebhooks = await prisma.webhook.findMany({ + where: { + OR: [ + { + userId, + }, + { + eventTypeId, + }, + ], + AND: { + eventTriggers: { + has: options.triggerEvent, + }, + active: { + equals: true, + }, + }, + }, + select: { + subscriberUrl: true, + payloadTemplate: true, + appId: true, + }, + }); + + return allWebhooks; +}; + +export default getWebhooks; From 664e697d40bc24232102221ed52443562f0b01b5 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Fri, 10 Jun 2022 11:42:01 +0530 Subject: [PATCH 03/19] add sendPayload file --- lib/utils/sendPayload.ts | 77 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 lib/utils/sendPayload.ts diff --git a/lib/utils/sendPayload.ts b/lib/utils/sendPayload.ts new file mode 100644 index 0000000000..62cc3f96d2 --- /dev/null +++ b/lib/utils/sendPayload.ts @@ -0,0 +1,77 @@ +import { Webhook } from "@prisma/client"; +import { compile } from "handlebars"; + +import type { CalendarEvent } from "@calcom/types/Calendar"; + +type ContentType = "application/json" | "application/x-www-form-urlencoded"; + +function applyTemplate(template: string, data: CalendarEvent, contentType: ContentType) { + const compiled = compile(template)(data); + if (contentType === "application/json") { + return JSON.stringify(jsonParse(compiled)); + } + return compiled; +} + +function jsonParse(jsonString: string) { + try { + return JSON.parse(jsonString); + } catch (e) { + // don't do anything. + } + return false; +} + +const sendPayload = async ( + triggerEvent: string, + createdAt: string, + webhook: Pick, + data: CalendarEvent & { + metadata?: { [key: string]: string }; + rescheduleUid?: string; + bookingId?: number; + } +) => { + const { subscriberUrl, appId, payloadTemplate: template } = webhook; + if (!subscriberUrl || !data) { + throw new Error("Missing required elements to send webhook payload."); + } + + const contentType = + !template || jsonParse(template) ? "application/json" : "application/x-www-form-urlencoded"; + + data.description = data.description || data.additionalNotes; + + let body; + + /* Zapier id is hardcoded in the DB, we send the raw data for this case */ + if (appId === "zapier") { + body = JSON.stringify(data); + } else if (template) { + body = applyTemplate(template, data, contentType); + } else { + body = JSON.stringify({ + triggerEvent: triggerEvent, + createdAt: createdAt, + payload: data, + }); + } + + const response = await fetch(subscriberUrl, { + method: "POST", + headers: { + "Content-Type": contentType, + }, + body, + }); + + const text = await response.text(); + + return { + ok: response.ok, + status: response.status, + message: text, + }; +}; + +export default sendPayload; From 542beb007938450ab0365aa4c6367a27cf6b5386 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Fri, 10 Jun 2022 11:46:51 +0530 Subject: [PATCH 04/19] adjust booking file --- pages/api/bookings/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index 1951e4475d..2ee5c2da1c 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -84,15 +84,17 @@ async function createOrlistAllBookings( if (booking) { res.status(201).json({ booking, message: "Booking created successfully" }); - // Send Webhook call if hooked to BOOKING_CREATED & BOOKING_RESCHEDULED -// const eventTrigger: WebhookTriggerEvents = rescheduleUid ? "BOOKING_RESCHEDULED" : "BOOKING_CREATED"; +// Create Calendar Event for webhook payload + +// Send Webhook call if hooked to BOOKING_CREATED & BOOKING_RESCHEDULED +// const eventTrigger = WebhookTriggerEvents.BOOKING_CREATED; // const subscriberOptions = { // userId: user.id, // eventTypeId, // triggerEvent: eventTrigger, // }; -// const subscribers = await getSubscribers(subscriberOptions); +// const subscribers = await getWebhooks(subscriberOptions); // const bookingId = booking?.id; // const promises = subscribers.map((sub) => // sendPayload(eventTrigger, new Date().toISOString(), sub, { From 804de678680f2fa991c904e1f0fb62f96a53bee5 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Fri, 10 Jun 2022 12:17:00 +0530 Subject: [PATCH 05/19] Add eventName file --- lib/utils/eventName.ts | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 lib/utils/eventName.ts diff --git a/lib/utils/eventName.ts b/lib/utils/eventName.ts new file mode 100644 index 0000000000..5d7865fe94 --- /dev/null +++ b/lib/utils/eventName.ts @@ -0,0 +1,62 @@ +import { TFunction } from "next-i18next"; + +type EventNameObjectType = { + attendeeName: string; + eventType: string; + eventName?: string | null; + host: string; + location?: string; + t: TFunction; +}; + +export function getEventName(eventNameObj: EventNameObjectType, forAttendeeView = false) { + if (!eventNameObj.eventName) + return eventNameObj.t("event_between_users", { + eventName: eventNameObj.eventType, + host: eventNameObj.host, + attendeeName: eventNameObj.attendeeName, + }); + + let eventName = eventNameObj.eventName; + let locationString = ""; + + if (eventNameObj.eventName.includes("{LOCATION}")) { + switch (eventNameObj.location) { + case "inPerson": + locationString = "In Person"; + break; + case "userPhone": + case "phone": + locationString = "Phone"; + break; + case "integrations:daily": + locationString = "Cal Video"; + break; + case "integrations:zoom": + locationString = "Zoom"; + break; + case "integrations:huddle01": + locationString = "Huddle01"; + break; + case "integrations:tandem": + locationString = "Tandem"; + break; + case "integrations:office365_video": + locationString = "MS Teams"; + break; + case "integrations:jitsi": + locationString = "Jitsi"; + break; + } + eventName = eventName.replace("{LOCATION}", locationString); + } + + return ( + eventName + // Need this for compatibility with older event names + .replace("{USER}", eventNameObj.attendeeName) + .replace("{ATTENDEE}", eventNameObj.attendeeName) + .replace("{HOST}", eventNameObj.host) + .replace("{HOST/ATTENDEE}", forAttendeeView ? eventNameObj.host : eventNameObj.attendeeName) + ); +} From e3822c50d0998312929a3c6b58e9c728c16a58ed Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Fri, 10 Jun 2022 12:43:41 +0530 Subject: [PATCH 06/19] Update booking file with webhook payload --- pages/api/bookings/index.ts | 78 +++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 21 deletions(-) diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index 2ee5c2da1c..f3b9e8c027 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -2,9 +2,14 @@ import type { NextApiRequest, NextApiResponse } from "next"; import prisma from "@calcom/prisma"; +import { WebhookTriggerEvents } from "@prisma/client"; + import { withMiddleware } from "@lib/helpers/withMiddleware"; +import sendPayload from "@lib/utils/sendPayload"; +import getWebhooks from "@lib/utils/webhookSubscriptions"; import { BookingResponse, BookingsResponse } from "@lib/types"; import { schemaBookingCreateBodyParams, schemaBookingReadPublic } from "@lib/validations/booking"; +import { schemaEventTypeReadPublic } from "@lib/validations/event-type"; async function createOrlistAllBookings( { method, body, userId }: NextApiRequest, @@ -84,29 +89,60 @@ async function createOrlistAllBookings( if (booking) { res.status(201).json({ booking, message: "Booking created successfully" }); -// Create Calendar Event for webhook payload + // Create Calendar Event for webhook payload + const eventType = await prisma.eventType + .findUnique({ where: { id: booking?.eventTypeId } }) + .then((data) => schemaEventTypeReadPublic.parse(data)) + .then((event_type) => res.status(200).json({ event_type })) + .catch((error: Error) => + res.status(404).json({ + message: `EventType with id: ${booking?.eventTypeId} not found`, + error, + }) + ); + const evt = { + type: eventType.title, + title: booking.title, + description: "", + additionalNotes: "", + customInputs: {}, + startTime: booking.startTime, + endTime: booking.endTime, + organizer: { + name: "", + email: "", + timezone: "", + language: { + locale: "en" + } + }, + attendees: [], + location: "", + destinationCalendar: null, + hideCalendar: false, + uid: booking.uid, + metadata: {} + }; -// Send Webhook call if hooked to BOOKING_CREATED & BOOKING_RESCHEDULED -// const eventTrigger = WebhookTriggerEvents.BOOKING_CREATED; -// const subscriberOptions = { -// userId: user.id, -// eventTypeId, -// triggerEvent: eventTrigger, -// }; + // Send Webhook call if hooked to BOOKING_CREATED + const triggerEvent = WebhookTriggerEvents.BOOKING_CREATED; + const subscriberOptions = { + userId, + eventTypeId: eventType.id, + triggerEvent, + }; -// const subscribers = await getWebhooks(subscriberOptions); -// const bookingId = booking?.id; -// const promises = subscribers.map((sub) => -// sendPayload(eventTrigger, new Date().toISOString(), sub, { -// ...evt, -// bookingId, -// rescheduleUid, -// metadata: reqBody.metadata, -// }).catch((e) => { -// console.error(`Error executing webhook for event: ${eventTrigger}, URL: ${sub.subscriberUrl}`, e); -// }) -// ); -// await Promise.all(promises); + const subscribers = await getWebhooks(subscriberOptions); + const bookingId = booking?.id; + const promises = subscribers.map((sub) => + sendPayload(eventTrigger, new Date().toISOString(), sub, { + ...evt, + bookingId, + }).catch((e) => { + console.error(`Error executing webhook for event: ${eventTrigger}, URL: ${sub.subscriberUrl}`, e); + }) + ); + await Promise.all(promises); } else (error: Error) => { From 4f3668100691dfb0f4fe8c622fd8bce513eed679 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz Date: Fri, 10 Jun 2022 12:51:24 +0530 Subject: [PATCH 07/19] --fix --- pages/api/bookings/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index f3b9e8c027..2a11672e32 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -135,11 +135,11 @@ async function createOrlistAllBookings( const subscribers = await getWebhooks(subscriberOptions); const bookingId = booking?.id; const promises = subscribers.map((sub) => - sendPayload(eventTrigger, new Date().toISOString(), sub, { + sendPayload(triggerEvent, new Date().toISOString(), sub, { ...evt, bookingId, }).catch((e) => { - console.error(`Error executing webhook for event: ${eventTrigger}, URL: ${sub.subscriberUrl}`, e); + console.error(`Error executing webhook for event: ${triggerEvent}, URL: ${sub.subscriberUrl}`, e); }) ); await Promise.all(promises); From f9c20bc8ce3544508585d8bb0fece077994da833 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz Date: Fri, 10 Jun 2022 12:53:59 +0530 Subject: [PATCH 08/19] --fix null estimated value --- pages/api/bookings/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index 2a11672e32..73c4e8d12b 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -91,7 +91,7 @@ async function createOrlistAllBookings( // Create Calendar Event for webhook payload const eventType = await prisma.eventType - .findUnique({ where: { id: booking?.eventTypeId } }) + .findUnique({ where: { id: booking.eventTypeId as number } }) .then((data) => schemaEventTypeReadPublic.parse(data)) .then((event_type) => res.status(200).json({ event_type })) .catch((error: Error) => From 4431142d4e540b8d0135241cff16d0c7d3fbff61 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz Date: Fri, 10 Jun 2022 12:58:04 +0530 Subject: [PATCH 09/19] remove unnecessary return --- pages/api/bookings/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index 73c4e8d12b..322543078f 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -93,10 +93,9 @@ async function createOrlistAllBookings( const eventType = await prisma.eventType .findUnique({ where: { id: booking.eventTypeId as number } }) .then((data) => schemaEventTypeReadPublic.parse(data)) - .then((event_type) => res.status(200).json({ event_type })) .catch((error: Error) => res.status(404).json({ - message: `EventType with id: ${booking?.eventTypeId} not found`, + message: `EventType with id: ${booking.eventTypeId} not found`, error, }) ); From adab79040f37e83e8ddc5aa4b59f079a21cacbc3 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz Date: Fri, 10 Jun 2022 13:06:22 +0530 Subject: [PATCH 10/19] --fix --- pages/api/bookings/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index 322543078f..2db7abac29 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -100,7 +100,7 @@ async function createOrlistAllBookings( }) ); const evt = { - type: eventType.title, + type: eventType?.title || booking.title, title: booking.title, description: "", additionalNotes: "", From cd3a80006c6eb3b44a17273439f729051406f613 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz Date: Fri, 10 Jun 2022 13:10:16 +0530 Subject: [PATCH 11/19] --fix --- pages/api/bookings/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index 2db7abac29..1b23a5e3f3 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -127,7 +127,7 @@ async function createOrlistAllBookings( const triggerEvent = WebhookTriggerEvents.BOOKING_CREATED; const subscriberOptions = { userId, - eventTypeId: eventType.id, + eventTypeId: booking.eventTypeId as number, triggerEvent, }; From a8ad052a037246219eb15cdb82d8dee798b8b057 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz Date: Fri, 10 Jun 2022 13:16:58 +0530 Subject: [PATCH 12/19] --convert date to string in calendar event --- pages/api/bookings/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index 1b23a5e3f3..0a421298e1 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -105,8 +105,8 @@ async function createOrlistAllBookings( description: "", additionalNotes: "", customInputs: {}, - startTime: booking.startTime, - endTime: booking.endTime, + startTime: booking.startTime.toISOString(), + endTime: booking.endTime.toISOString(), organizer: { name: "", email: "", From ef5bbfe4f96c65480beb7bc88519464368700cdf Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz Date: Fri, 10 Jun 2022 13:22:06 +0530 Subject: [PATCH 13/19] fixed timeZone key --- pages/api/bookings/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index 0a421298e1..a8eaf90662 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -110,7 +110,7 @@ async function createOrlistAllBookings( organizer: { name: "", email: "", - timezone: "", + timeZone: "", language: { locale: "en" } From f1c98181d2daee95d3e16ba25406010914aa8e78 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz Date: Fri, 10 Jun 2022 13:30:43 +0530 Subject: [PATCH 14/19] tfunction added --- pages/api/bookings/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index a8eaf90662..f5748daf67 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -1,5 +1,6 @@ -import type { NextApiRequest, NextApiResponse } from "next"; +import { getTranslation } from "@calcom/lib/server/i18n"; +import type { NextApiRequest, NextApiResponse } from "next"; import prisma from "@calcom/prisma"; import { WebhookTriggerEvents } from "@prisma/client"; @@ -99,6 +100,7 @@ async function createOrlistAllBookings( error, }) ); + const fallbackTfunction = await getTranslation("en", "common"); const evt = { type: eventType?.title || booking.title, title: booking.title, @@ -112,6 +114,7 @@ async function createOrlistAllBookings( email: "", timeZone: "", language: { + translate: fallbackTfunction, locale: "en" } }, From 54353f99d139395826a270843ad57abd73c38d1d Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz Date: Fri, 10 Jun 2022 13:32:47 +0530 Subject: [PATCH 15/19] Calendar event changed to any for loose allowance --- lib/utils/sendPayload.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/utils/sendPayload.ts b/lib/utils/sendPayload.ts index 62cc3f96d2..925be7486a 100644 --- a/lib/utils/sendPayload.ts +++ b/lib/utils/sendPayload.ts @@ -1,11 +1,11 @@ import { Webhook } from "@prisma/client"; import { compile } from "handlebars"; -import type { CalendarEvent } from "@calcom/types/Calendar"; +// import type { CalendarEvent } from "@calcom/types/Calendar"; Add this to make it strict, change data: any to CalendarEvent type type ContentType = "application/json" | "application/x-www-form-urlencoded"; -function applyTemplate(template: string, data: CalendarEvent, contentType: ContentType) { +function applyTemplate(template: string, data: any, contentType: ContentType) { const compiled = compile(template)(data); if (contentType === "application/json") { return JSON.stringify(jsonParse(compiled)); From 8339d339a1ac3f149045e7fa0a180107ea585ce7 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz Date: Fri, 10 Jun 2022 13:38:45 +0530 Subject: [PATCH 16/19] prettier and payload fix --- lib/utils/sendPayload.ts | 2 +- pages/api/bookings/index.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/utils/sendPayload.ts b/lib/utils/sendPayload.ts index 925be7486a..f40c0ad743 100644 --- a/lib/utils/sendPayload.ts +++ b/lib/utils/sendPayload.ts @@ -26,7 +26,7 @@ const sendPayload = async ( triggerEvent: string, createdAt: string, webhook: Pick, - data: CalendarEvent & { + data: any & { metadata?: { [key: string]: string }; rescheduleUid?: string; bookingId?: number; diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index f5748daf67..7abd8ae5e7 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -1,14 +1,14 @@ -import { getTranslation } from "@calcom/lib/server/i18n"; - -import type { NextApiRequest, NextApiResponse } from "next"; import prisma from "@calcom/prisma"; import { WebhookTriggerEvents } from "@prisma/client"; +import { getTranslation } from "@calcom/lib/server/i18n"; + +import type { NextApiRequest, NextApiResponse } from "next"; import { withMiddleware } from "@lib/helpers/withMiddleware"; +import { BookingResponse, BookingsResponse } from "@lib/types"; import sendPayload from "@lib/utils/sendPayload"; import getWebhooks from "@lib/utils/webhookSubscriptions"; -import { BookingResponse, BookingsResponse } from "@lib/types"; import { schemaBookingCreateBodyParams, schemaBookingReadPublic } from "@lib/validations/booking"; import { schemaEventTypeReadPublic } from "@lib/validations/event-type"; @@ -115,7 +115,7 @@ async function createOrlistAllBookings( timeZone: "", language: { translate: fallbackTfunction, - locale: "en" + locale: "en", } }, attendees: [], From 5453af6d6ee189185b0c467157013d821825d7cd Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz Date: Fri, 10 Jun 2022 15:57:31 +0530 Subject: [PATCH 17/19] prettier fix attempt --- pages/api/bookings/index.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index 7abd8ae5e7..4db3f3051a 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -1,10 +1,9 @@ -import prisma from "@calcom/prisma"; - import { WebhookTriggerEvents } from "@prisma/client"; -import { getTranslation } from "@calcom/lib/server/i18n"; - import type { NextApiRequest, NextApiResponse } from "next"; +import { getTranslation } from "@calcom/lib/server/i18n"; +import prisma from "@calcom/prisma"; + import { withMiddleware } from "@lib/helpers/withMiddleware"; import { BookingResponse, BookingsResponse } from "@lib/types"; import sendPayload from "@lib/utils/sendPayload"; From 301c132815bd011f47efae13f21b053704664158 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz Date: Fri, 10 Jun 2022 16:21:55 +0530 Subject: [PATCH 18/19] prettier fix attempt-2 --- pages/api/bookings/index.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index 4db3f3051a..b8ef582dc1 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -88,8 +88,7 @@ async function createOrlistAllBookings( if (booking) { res.status(201).json({ booking, message: "Booking created successfully" }); - - // Create Calendar Event for webhook payload + // Create Calendar Event for webhook payload const eventType = await prisma.eventType .findUnique({ where: { id: booking.eventTypeId as number } }) .then((data) => schemaEventTypeReadPublic.parse(data)) @@ -115,24 +114,24 @@ async function createOrlistAllBookings( language: { translate: fallbackTfunction, locale: "en", - } + }, }, attendees: [], location: "", destinationCalendar: null, hideCalendar: false, uid: booking.uid, - metadata: {} + metadata: {}, }; - - // Send Webhook call if hooked to BOOKING_CREATED + + // Send Webhook call if hooked to BOOKING_CREATED const triggerEvent = WebhookTriggerEvents.BOOKING_CREATED; const subscriberOptions = { userId, eventTypeId: booking.eventTypeId as number, triggerEvent, }; - + const subscribers = await getWebhooks(subscriberOptions); const bookingId = booking?.id; const promises = subscribers.map((sub) => From 99e58c414c0419b96d9a0fe0c6e992c62307788f Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz Date: Fri, 10 Jun 2022 16:36:28 +0530 Subject: [PATCH 19/19] prettier fix -3 --- pages/api/bookings/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index b8ef582dc1..90f9cf7f22 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -143,8 +143,7 @@ async function createOrlistAllBookings( }) ); await Promise.all(promises); - } - else + } else (error: Error) => { console.log(error); res.status(400).json({