From 4629c5d5c77a7594754d36060c805617682b973f Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Mon, 23 May 2022 23:18:41 +0200 Subject: [PATCH 01/25] fix: move log of userId --- pages/api/event-types/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index c3a7cc954f..1ab736eec2 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -10,6 +10,7 @@ async function createOrlistAllEventTypes( { method, body, userId }: NextApiRequest, res: NextApiResponse ) { + console.log("userId:", userId); if (method === "GET") { /** * @swagger @@ -33,7 +34,6 @@ async function createOrlistAllEventTypes( .findMany({ where: { userId } }) .catch((error) => res.status(404).json({ message: "No event types were found", error })); console.log("eventTypes:", data); - console.log("userId:", userId); // const event_types = data.map( // async (eventType) => await schemaEventTypeReadPublic.safeParseAsync(eventType) // ); From 6099bfb4ee5904ea73bb0dbd2c1e94b53172a747 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Mon, 23 May 2022 23:23:53 +0200 Subject: [PATCH 02/25] fix: more logging --- lib/helpers/verifyApiKey.ts | 1 + pages/api/event-types/index.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index 38fa6b44c3..11d481815e 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -40,5 +40,6 @@ export const verifyApiKey: NextMiddleware = async (req, res, next) => { if (!apiKey.userId) return res.status(404).json({ error: "No user found for this apiKey" }); /* We save the user id in the request for later use */ req.userId = apiKey.userId; + console.log(`User ${apiKey.userId} verified`); await next(); }; diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index 1ab736eec2..ccbf79d7ca 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -33,7 +33,7 @@ async function createOrlistAllEventTypes( const data = await prisma.eventType .findMany({ where: { userId } }) .catch((error) => res.status(404).json({ message: "No event types were found", error })); - console.log("eventTypes:", data); + console.log(`userid is: ${userId}`, "eventTypes:", data); // const event_types = data.map( // async (eventType) => await schemaEventTypeReadPublic.safeParseAsync(eventType) // ); From a945d5a61c7d713a0050ef8e4cf7fb8ec4964a43 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Wed, 25 May 2022 14:13:52 +0530 Subject: [PATCH 03/25] Enabled webhook create call --- pages/api/hooks/index.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pages/api/hooks/index.ts b/pages/api/hooks/index.ts index 983fe3ecce..05b6e90d57 100644 --- a/pages/api/hooks/index.ts +++ b/pages/api/hooks/index.ts @@ -55,19 +55,19 @@ async function createOrlistAllWebhooks( * 401: * description: Authorization information is missing or invalid. */ - // const safe = schemaWebhookCreateBodyParams.safeParse(body); - // if (!safe.success) { - // res.status(400).json({ message: "Invalid request body" }); - // return; - // } - // const data = await prisma.webhook.create({ data: { ...safe.data, userId } }); - // if (data) res.status(201).json({ webhook: data, message: "Webhook created successfully" }); - // else - // (error: Error) => - // res.status(400).json({ - // message: "Could not create new webhook", - // error, - // }); + const safe = schemaWebhookCreateBodyParams.safeParse(body); + if (!safe.success) { + res.status(400).json({ message: "Invalid request body" }); + return; + } + const data = await prisma.webhook.create({ data: { ...safe.data, userId } }); + if (data) res.status(201).json({ webhook: data, message: "Webhook created successfully" }); + else + (error: Error) => + res.status(400).json({ + message: "Could not create new webhook", + error, + }); } else res.status(405).json({ message: `Method ${method} not allowed` }); } From fe3f6a70f3bbb6f5ed342f5b84e5a9400afaf583 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Wed, 25 May 2022 14:23:43 +0530 Subject: [PATCH 04/25] Added schema for create --- lib/validations/webhook.ts | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index aab40dc502..a655e5f11c 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -12,29 +12,21 @@ const schemaWebhookBaseBodyParams = Webhook.pick({ payloadTemplate: true, }).partial(); -// const schemaWebhookCreateParams = z -// .object({ -// id: z.string(), -// subscriberUrl: z.string(), -// }) -// .strict(); +export const schemaWebhookCreateParams = z + .object({ + userId: z.number().or(z.string()).optional(), + eventTypeId: z.number().or(z.string()).optional(), + eventTriggers: z.any.optional(), + active: z.boolean().optional(), + subscriberUrl: z.string(), + payloadTemplate: z.string().optional(), + }) + .strict(); export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge( - z.object({ - id: z.string(), - subscriberUrl: z.string(), - }) + schemaWebhookCreateParams ); -// const schemaWebhookEditParams = z -// .object({ -// payloadTemplate: z.string().optional(), -// /** @todo: don't use any here and validate eventTriggers proper */ -// eventTriggers: z.any(), -// subscriberUrl: z.string().optional(), -// }) -// .strict(); - export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams.merge( z.object({ payloadTemplate: z.string().optional(), From 2109001af13577ef182fd8a0e99e77c92ec7fc19 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Wed, 25 May 2022 15:07:19 +0530 Subject: [PATCH 05/25] Fixes any invocation --- lib/validations/webhook.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index a655e5f11c..40aec5c288 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -16,7 +16,7 @@ export const schemaWebhookCreateParams = z .object({ userId: z.number().or(z.string()).optional(), eventTypeId: z.number().or(z.string()).optional(), - eventTriggers: z.any.optional(), + eventTriggers: z.any().optional(), active: z.boolean().optional(), subscriberUrl: z.string(), payloadTemplate: z.string().optional(), From 4aba0af1b46f2d19291e7d76bac96fce04651d3c Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 11:20:49 +0530 Subject: [PATCH 06/25] Updated webhook validations --- lib/validations/webhook.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index 40aec5c288..86b811739c 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -1,9 +1,15 @@ import { z } from "zod"; import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; +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"]; const schemaWebhookBaseBodyParams = Webhook.pick({ - id: true, userId: true, eventTypeId: true, eventTriggers: true, @@ -14,12 +20,12 @@ const schemaWebhookBaseBodyParams = Webhook.pick({ export const schemaWebhookCreateParams = z .object({ - userId: z.number().or(z.string()).optional(), - eventTypeId: z.number().or(z.string()).optional(), - eventTriggers: z.any().optional(), - active: z.boolean().optional(), - subscriberUrl: z.string(), - payloadTemplate: z.string().optional(), + subscriberUrl: z.string().url(), + eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array(), + active: z.boolean(), + payloadTemplate: z.string().nullable(), + eventTypeId: z.number().optional(), + appId: z.string().optional().nullable(), }) .strict(); @@ -30,8 +36,8 @@ 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(), + /** @todo: don't use 'any' here and validate eventTriggers proper */ + eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array().optional(), subscriberUrl: z.string().optional(), }) ); From 7c6141fdffcb86532feb3f1cee5d8bdfa0934ceb Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 11:41:36 +0530 Subject: [PATCH 07/25] Debug create err --- lib/validations/webhook.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index 86b811739c..b228f47e42 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -1,13 +1,13 @@ 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({ userId: true, @@ -21,7 +21,7 @@ const schemaWebhookBaseBodyParams = Webhook.pick({ export const schemaWebhookCreateParams = z .object({ subscriberUrl: z.string().url(), - eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array(), + eventTriggers: z.any(), active: z.boolean(), payloadTemplate: z.string().nullable(), eventTypeId: z.number().optional(), @@ -37,7 +37,7 @@ export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams.merge( z.object({ 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(), }) ); From fbe3d2fd101946fc44300c422da7fd8a55fe7fe3 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:03:14 +0530 Subject: [PATCH 08/25] more debug --- lib/validations/webhook.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index b228f47e42..48665c61d1 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -21,9 +21,9 @@ const schemaWebhookBaseBodyParams = Webhook.pick({ export const schemaWebhookCreateParams = z .object({ subscriberUrl: z.string().url(), - eventTriggers: z.any(), + eventTriggers: z.string().array(), active: z.boolean(), - payloadTemplate: z.string().nullable(), + payloadTemplate: z.string().optional().nullable(), eventTypeId: z.number().optional(), appId: z.string().optional().nullable(), }) From 014a682d64138375d07899d17f1928d15ed2c18e Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:06:15 +0530 Subject: [PATCH 09/25] More debug --- lib/validations/webhook.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index 48665c61d1..44f433b3c1 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -21,11 +21,11 @@ const schemaWebhookBaseBodyParams = Webhook.pick({ export const schemaWebhookCreateParams = z .object({ subscriberUrl: z.string().url(), - eventTriggers: z.string().array(), + eventTriggers: z.any(), 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(); 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 10/25] 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(), }) ); From 4c7dc10f7dc35661d3b23cbc8b29c03687413bdf Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:16:51 +0530 Subject: [PATCH 11/25] Fixing prettier --- lib/validations/webhook.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index f523c4c71e..1997bdbb3e 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -1,8 +1,9 @@ import { z } from "zod"; -import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; import { WebhookTriggerEvents } from "@calcom/prisma/client"; +import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; + export const WEBHOOK_TRIGGER_EVENTS = [ WebhookTriggerEvents.BOOKING_CANCELLED, WebhookTriggerEvents.BOOKING_CREATED, @@ -31,9 +32,7 @@ export const schemaWebhookCreateParams = z }) .strict(); -export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge( - schemaWebhookCreateParams -); +export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge(schemaWebhookCreateParams); export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams.merge( z.object({ From 81793aebcddaefce090b2dd5a6bb352b2c4092dd Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:20:32 +0530 Subject: [PATCH 12/25] Further prettier changes --- lib/validations/webhook.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index 1997bdbb3e..d7109e5912 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -1,7 +1,6 @@ import { z } from "zod"; import { WebhookTriggerEvents } from "@calcom/prisma/client"; - import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; export const WEBHOOK_TRIGGER_EVENTS = [ From c185883e5a2c07d1a8901ed0a7c2d16edde942be Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:25:13 +0530 Subject: [PATCH 13/25] Fixed enum --- lib/validations/webhook.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index d7109e5912..b2d6485275 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -1,8 +1,13 @@ import { z } from "zod"; -import { WebhookTriggerEvents } from "@calcom/prisma/client"; import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; +export const WebhookTriggerEvents: { + BOOKING_CREATED: 'BOOKING_CREATED', + BOOKING_RESCHEDULED: 'BOOKING_RESCHEDULED', + BOOKING_CANCELLED: 'BOOKING_CANCELLED' +}; + export const WEBHOOK_TRIGGER_EVENTS = [ WebhookTriggerEvents.BOOKING_CANCELLED, WebhookTriggerEvents.BOOKING_CREATED, From c47329c2929eaca5ae0f027fa09249e284084c7f Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:28:38 +0530 Subject: [PATCH 14/25] More fix --- lib/validations/webhook.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index b2d6485275..6c35fb9743 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -2,7 +2,7 @@ import { z } from "zod"; import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; -export const WebhookTriggerEvents: { +export const WebhookTriggerEvents = { BOOKING_CREATED: 'BOOKING_CREATED', BOOKING_RESCHEDULED: 'BOOKING_RESCHEDULED', BOOKING_CANCELLED: 'BOOKING_CANCELLED' From de557fccce691d93dfb7c15f4ad533ec5d5ac35e Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:32:04 +0530 Subject: [PATCH 15/25] prettier fix --- lib/validations/webhook.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index 6c35fb9743..59da7bb71a 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -3,9 +3,9 @@ import { z } from "zod"; import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; export const WebhookTriggerEvents = { - BOOKING_CREATED: 'BOOKING_CREATED', - BOOKING_RESCHEDULED: 'BOOKING_RESCHEDULED', - BOOKING_CANCELLED: 'BOOKING_CANCELLED' + BOOKING_CREATED: "BOOKING_CREATED", + BOOKING_RESCHEDULED: "BOOKING_RESCHEDULED", + BOOKING_CANCELLED: "BOOKING_CANCELLED" }; export const WEBHOOK_TRIGGER_EVENTS = [ From 49ef2c341d4c869feff1d4539a2297840a20bc7b Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 26 May 2022 12:35:28 +0530 Subject: [PATCH 16/25] prettier fix again --- lib/validations/webhook.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index 59da7bb71a..ee42052204 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -5,7 +5,7 @@ import { _WebhookModel as Webhook } from "@calcom/prisma/zod"; export const WebhookTriggerEvents = { BOOKING_CREATED: "BOOKING_CREATED", BOOKING_RESCHEDULED: "BOOKING_RESCHEDULED", - BOOKING_CANCELLED: "BOOKING_CANCELLED" + BOOKING_CANCELLED: "BOOKING_CANCELLED", }; export const WEBHOOK_TRIGGER_EVENTS = [ From 46e0b8f4f5084725582fb93f3299fd4529a0bca0 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 27 May 2022 20:43:10 +0200 Subject: [PATCH 17/25] fix: moves event-types to find user including it's event-types --- pages/api/event-types/index.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index ccbf79d7ca..e5660f138f 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -30,14 +30,14 @@ async function createOrlistAllEventTypes( * 404: * description: No event types were found */ - const data = await prisma.eventType - .findMany({ where: { userId } }) + const data = await prisma.user + .findUnique({ + where: { id: userId }, + rejectOnNotFound: true, + select: { eventTypes: true }, + }) .catch((error) => res.status(404).json({ message: "No event types were found", error })); - console.log(`userid is: ${userId}`, "eventTypes:", data); - // const event_types = data.map( - // async (eventType) => await schemaEventTypeReadPublic.safeParseAsync(eventType) - // ); - if (data) res.status(200).json({ event_types: data }); + if (data) res.status(200).json({ event_types: data.eventTypes }); else (error: Error) => res.status(404).json({ From d09fa56f631387e9bb2763134861582cb39abb28 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 27 May 2022 20:47:02 +0200 Subject: [PATCH 18/25] fix --- pages/api/event-types/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index e5660f138f..5c895a9165 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -37,6 +37,16 @@ async function createOrlistAllEventTypes( select: { eventTypes: true }, }) .catch((error) => res.status(404).json({ message: "No event types were found", error })); +<<<<<<< HEAD +======= +<<<<<<< HEAD +======= + console.log(`userid is: ${userId}`, "eventTypes:", data); +>>>>>>> 6099bfb (fix: more logging) + // const event_types = data.map( + // async (eventType) => await schemaEventTypeReadPublic.safeParseAsync(eventType) + // ); +>>>>>>> d374031 (fix: more logging) if (data) res.status(200).json({ event_types: data.eventTypes }); else (error: Error) => From 9f509725702200f86eca958b928f2b32502d2cc2 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 27 May 2022 20:49:50 +0200 Subject: [PATCH 19/25] fix event-types --- pages/api/event-types/index.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index 5c895a9165..786d4453f3 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -37,16 +37,7 @@ async function createOrlistAllEventTypes( select: { eventTypes: true }, }) .catch((error) => res.status(404).json({ message: "No event types were found", error })); -<<<<<<< HEAD -======= -<<<<<<< HEAD -======= - console.log(`userid is: ${userId}`, "eventTypes:", data); ->>>>>>> 6099bfb (fix: more logging) - // const event_types = data.map( - // async (eventType) => await schemaEventTypeReadPublic.safeParseAsync(eventType) - // ); ->>>>>>> d374031 (fix: more logging) + if (data) res.status(200).json({ event_types: data.eventTypes }); else (error: Error) => From a91dd428c0c8f14e66b58beabfeabdf3c9224aa7 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 27 May 2022 21:01:01 +0200 Subject: [PATCH 20/25] fix --- lib/helpers/verifyApiKey.ts | 1 - pages/api/event-types/index.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index 11d481815e..38fa6b44c3 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -40,6 +40,5 @@ export const verifyApiKey: NextMiddleware = async (req, res, next) => { if (!apiKey.userId) return res.status(404).json({ error: "No user found for this apiKey" }); /* We save the user id in the request for later use */ req.userId = apiKey.userId; - console.log(`User ${apiKey.userId} verified`); await next(); }; diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index 786d4453f3..b5c82ef67d 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -10,7 +10,6 @@ async function createOrlistAllEventTypes( { method, body, userId }: NextApiRequest, res: NextApiResponse ) { - console.log("userId:", userId); if (method === "GET") { /** * @swagger From 824d01f3588fdfbfd6add42be2dbb7240271f212 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Mon, 23 May 2022 23:18:41 +0200 Subject: [PATCH 21/25] fix: move log of userId --- pages/api/event-types/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index b5c82ef67d..786d4453f3 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -10,6 +10,7 @@ async function createOrlistAllEventTypes( { method, body, userId }: NextApiRequest, res: NextApiResponse ) { + console.log("userId:", userId); if (method === "GET") { /** * @swagger From 5b65bd1b660592bf417b1c687df596603373421e Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 27 May 2022 20:48:21 +0200 Subject: [PATCH 22/25] fix --- lib/helpers/verifyApiKey.ts | 1 + pages/api/event-types/index.ts | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index 38fa6b44c3..11d481815e 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -40,5 +40,6 @@ export const verifyApiKey: NextMiddleware = async (req, res, next) => { if (!apiKey.userId) return res.status(404).json({ error: "No user found for this apiKey" }); /* We save the user id in the request for later use */ req.userId = apiKey.userId; + console.log(`User ${apiKey.userId} verified`); await next(); }; diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index 786d4453f3..57ebba1ce4 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -37,8 +37,16 @@ async function createOrlistAllEventTypes( select: { eventTypes: true }, }) .catch((error) => res.status(404).json({ message: "No event types were found", error })); +<<<<<<< HEAD if (data) res.status(200).json({ event_types: data.eventTypes }); +======= + console.log(`userid is: ${userId}`, "eventTypes:", data); + // const event_types = data.map( + // async (eventType) => await schemaEventTypeReadPublic.safeParseAsync(eventType) + // ); + if (data) res.status(200).json({ event_types: data }); +>>>>>>> 6099bfb (fix: more logging) else (error: Error) => res.status(404).json({ From f40e799769062b7677b7d75abe6baf0b86690a61 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 27 May 2022 20:48:55 +0200 Subject: [PATCH 23/25] fix event types --- pages/api/event-types/index.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index 57ebba1ce4..ceb8ef269b 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -37,16 +37,13 @@ async function createOrlistAllEventTypes( select: { eventTypes: true }, }) .catch((error) => res.status(404).json({ message: "No event types were found", error })); -<<<<<<< HEAD - if (data) res.status(200).json({ event_types: data.eventTypes }); -======= + console.log(`userid is: ${userId}`, "eventTypes:", data); // const event_types = data.map( // async (eventType) => await schemaEventTypeReadPublic.safeParseAsync(eventType) // ); - if (data) res.status(200).json({ event_types: data }); ->>>>>>> 6099bfb (fix: more logging) + if (data) res.status(200).json({ event_types: data.eventTypes }); else (error: Error) => res.status(404).json({ From b52832f333f3e3246d94ad0157d3683cd629bdf1 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 27 May 2022 20:47:02 +0200 Subject: [PATCH 24/25] fix --- pages/api/event-types/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index ceb8ef269b..178b37028c 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -37,6 +37,16 @@ async function createOrlistAllEventTypes( select: { eventTypes: true }, }) .catch((error) => res.status(404).json({ message: "No event types were found", error })); +<<<<<<< HEAD +======= +<<<<<<< HEAD +======= + console.log(`userid is: ${userId}`, "eventTypes:", data); +>>>>>>> 6099bfb (fix: more logging) + // const event_types = data.map( + // async (eventType) => await schemaEventTypeReadPublic.safeParseAsync(eventType) + // ); +>>>>>>> d374031 (fix: more logging) if (data) res.status(200).json({ event_types: data.eventTypes }); console.log(`userid is: ${userId}`, "eventTypes:", data); From 8627b28a8ea6da4cf40463b5d4334e7ff20a78a8 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 27 May 2022 21:18:47 +0200 Subject: [PATCH 25/25] fix: conflicts --- lib/helpers/verifyApiKey.ts | 1 - pages/api/event-types/index.ts | 16 ---------------- 2 files changed, 17 deletions(-) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index 11d481815e..38fa6b44c3 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -40,6 +40,5 @@ export const verifyApiKey: NextMiddleware = async (req, res, next) => { if (!apiKey.userId) return res.status(404).json({ error: "No user found for this apiKey" }); /* We save the user id in the request for later use */ req.userId = apiKey.userId; - console.log(`User ${apiKey.userId} verified`); await next(); }; diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index 178b37028c..b5c82ef67d 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -10,7 +10,6 @@ async function createOrlistAllEventTypes( { method, body, userId }: NextApiRequest, res: NextApiResponse ) { - console.log("userId:", userId); if (method === "GET") { /** * @swagger @@ -37,22 +36,7 @@ async function createOrlistAllEventTypes( select: { eventTypes: true }, }) .catch((error) => res.status(404).json({ message: "No event types were found", error })); -<<<<<<< HEAD -======= -<<<<<<< HEAD -======= - console.log(`userid is: ${userId}`, "eventTypes:", data); ->>>>>>> 6099bfb (fix: more logging) - // const event_types = data.map( - // async (eventType) => await schemaEventTypeReadPublic.safeParseAsync(eventType) - // ); ->>>>>>> d374031 (fix: more logging) - if (data) res.status(200).json({ event_types: data.eventTypes }); - console.log(`userid is: ${userId}`, "eventTypes:", data); - // const event_types = data.map( - // async (eventType) => await schemaEventTypeReadPublic.safeParseAsync(eventType) - // ); if (data) res.status(200).json({ event_types: data.eventTypes }); else (error: Error) =>