From f2ce2f324bcf4df5efdce164f6a7a2f734df324b Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 20 May 2022 00:58:42 +0200 Subject: [PATCH 01/10] fix: build webhooks and event-types --- lib/helpers/verifyApiKey.ts | 24 +- lib/types.ts | 1 + lib/validations/webhook.ts | 2 +- package.json | 1 - pages/api/booking-references/[id].ts | 324 +++++++++++++-------------- pages/api/users/index.ts | 23 +- 6 files changed, 188 insertions(+), 187 deletions(-) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index 81bbb8db07..2c58befc4d 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -1,19 +1,21 @@ -import type { IncomingMessage } from "http"; +// import type { NextApiRequest } from "next"; import { NextMiddleware } from "next-api-middleware"; import { hashAPIKey } from "@calcom/ee/lib/api/apiKeys"; import prisma from "@calcom/prisma"; -/** @todo figure how to use the one from `@calcom/types`fi */ -/** @todo: remove once `@calcom/types` is updated with it.*/ -declare module "next" { - export interface NextApiRequest extends IncomingMessage { - userId: number; - query: { - apiKey: string; - }; - } -} +// /** @todo figure how to use the one from `@calcom/types`fi */ +// /** @todo: remove once `@calcom/types` is updated with it.*/ +// declare module "next" { +// export interface NextApiRequest extends NextApiRequest { +// userId: number; +// body: any; +// method: string; +// query: { +// apiKey: string; +// }; +// } +// } // Used to check if the apiKey is not expired, could be extracted if reused. but not for now. export const dateNotInPast = function (date: Date) { diff --git a/lib/types.ts b/lib/types.ts index a5c7d8ad21..6018019abc 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -150,6 +150,7 @@ interface EventTypeExtended extends Omit; diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index dc8f8bb41f..5948db65eb 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -24,7 +24,7 @@ export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge(s const schemaWebhookEditParams = z .object({ payloadTemplate: z.string().optional(), - eventTriggers: z.string().optional(), + eventTriggers: z.any(), subscriberUrl: z.string().optional(), }) .strict(); diff --git a/package.json b/package.json index 8f025ebd54..33dd0c54a7 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ }, "devDependencies": { "@calcom/tsconfig": "*", - "@calcom/types": "*", "@typescript-eslint/eslint-plugin": "^5.25.0", "babel-jest": "^28.1.0", "jest": "^28.0.3", diff --git a/pages/api/booking-references/[id].ts b/pages/api/booking-references/[id].ts index 702b77c1a5..47a76ea85e 100644 --- a/pages/api/booking-references/[id].ts +++ b/pages/api/booking-references/[id].ts @@ -22,177 +22,177 @@ export async function bookingReferenceById( res.status(400).json({ message: "Your query was invalid" }); return; } - // const userWithBookings = await prisma.user.findUnique({ - // where: { id: userId }, - // include: { bookings: true }, - // }); - // if (!userWithBookings) throw new Error("User not found"); - // const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat(); + const userWithBookings = await prisma.user.findUnique({ + where: { id: userId }, + include: { bookings: true }, + }); + if (!userWithBookings) throw new Error("User not found"); + const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat(); // console.log(userBookingIds); - // const bookingReferences = await prisma.bookingReference - // .findMany({ where: { id: { in: userBookingIds } } }) - // .then((bookingReferences) => { - // console.log(bookingReferences); - // return bookingReferences.map((bookingReference) => bookingReference.id); - // }); + const bookingReferences = await prisma.bookingReference + .findMany({ where: { id: { in: userBookingIds } } }) + .then((bookingReferences) => { + console.log(bookingReferences); + return bookingReferences.map((bookingReference) => bookingReference.id); + }); // res.status(400).json({ message: "Booking reference not found" }); // return; // } - // if (userBookingIds.includes(safeQuery.data.id)) { - // if (!bookingReferences?.includes(safeQuery.data.id)) { - // throw new Error("BookingReference: bookingId not found"); - switch (method) { - case "GET": - /** - * @swagger - * /booking-references/{id}: - * get: - * operationId: getBookingReferenceById - * summary: Find a booking reference - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: ID of the booking reference to get - * tags: - * - booking-references - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: BookingReference was not found - */ - // console.log(safeQuery.data.id); - const bookingReference = await prisma.bookingReference.findFirst().catch((error: Error) => { - console.log("hoerr:", error); - }); - // console.log(bookingReference); - if (!bookingReference) res.status(404).json({ message: "Booking reference not found" }); - else res.status(200).json({ booking_reference: bookingReference }); + if (!bookingReferences?.includes(safeQuery.data.id)) { + // if (userBookingIds.includes(safeQuery.data.id)) { + // throw new Error("BookingReference: bookingId not found"); + switch (method) { + case "GET": + /** + * @swagger + * /booking-references/{id}: + * get: + * operationId: getBookingReferenceById + * summary: Find a booking reference + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: ID of the booking reference to get + * tags: + * - booking-references + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: BookingReference was not found + */ + // console.log(safeQuery.data.id); + const bookingReference = await prisma.bookingReference.findFirst().catch((error: Error) => { + console.log("hoerr:", error); + }); + // console.log(bookingReference); + if (!bookingReference) res.status(404).json({ message: "Booking reference not found" }); + else res.status(200).json({ booking_reference: bookingReference }); - // .then((data) => { - // console.log(data); - // return schemaBookingReferenceReadPublic.parse(data); - // }) - // .then((booking_reference) => res.status(200).json({ booking_reference })) - // .catch((error: Error) => { - // console.log(error); - // res.status(404).json({ - // message: `BookingReference with id: ${safeQuery.data.id} not found`, - // error, - // }); - // }); - break; - case "PATCH": - /** - * @swagger - * /booking-references/{id}: - * patch: - * operationId: editBookingReferenceById - * summary: Edit an existing booking reference - * requestBody: - * description: Edit an existing booking reference related to one of your bookings - * required: true - * content: - * application/json: - * schema: - * type: object - * properties: - * days: - * type: array - * example: email@example.com - * startTime: - * type: string - * example: 1970-01-01T17:00:00.000Z - * endTime: - * type: string - * example: 1970-01-01T17:00:00.000Z - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: ID of the booking reference to edit - * tags: - * - booking-references - * responses: - * 201: - * description: OK, safeBody.data edited successfuly - * 400: - * description: Bad request. BookingReference body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ + // .then((data) => { + // console.log(data); + // return schemaBookingReferenceReadPublic.parse(data); + // }) + // .then((booking_reference) => res.status(200).json({ booking_reference })) + // .catch((error: Error) => { + // console.log(error); + // res.status(404).json({ + // message: `BookingReference with id: ${safeQuery.data.id} not found`, + // error, + // }); + // }); + break; + case "PATCH": + /** + * @swagger + * /booking-references/{id}: + * patch: + * operationId: editBookingReferenceById + * summary: Edit an existing booking reference + * requestBody: + * description: Edit an existing booking reference related to one of your bookings + * required: true + * content: + * application/json: + * schema: + * type: object + * properties: + * days: + * type: array + * example: email@example.com + * startTime: + * type: string + * example: 1970-01-01T17:00:00.000Z + * endTime: + * type: string + * example: 1970-01-01T17:00:00.000Z + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: ID of the booking reference to edit + * tags: + * - booking-references + * responses: + * 201: + * description: OK, safeBody.data edited successfuly + * 400: + * description: Bad request. BookingReference body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ - const safeBody = schemaBookingEditBodyParams.safeParse(body); - if (!safeBody.success) { - console.log(safeBody.error); - res.status(400).json({ message: "Invalid request body", error: safeBody.error }); - return; - } - await prisma.bookingReference - .update({ where: { id: safeQuery.data.id }, data: safeBody.data }) - .then((data) => schemaBookingReferenceReadPublic.parse(data)) - .then((booking_reference) => res.status(200).json({ booking_reference })) - .catch((error: Error) => - res.status(404).json({ - message: `BookingReference with id: ${safeQuery.data.id} not found`, - error, + const safeBody = schemaBookingEditBodyParams.safeParse(body); + if (!safeBody.success) { + console.log(safeBody.error); + res.status(400).json({ message: "Invalid request body", error: safeBody.error }); + return; + } + await prisma.bookingReference + .update({ where: { id: safeQuery.data.id }, data: safeBody.data }) + .then((data) => schemaBookingReferenceReadPublic.parse(data)) + .then((booking_reference) => res.status(200).json({ booking_reference })) + .catch((error: Error) => + res.status(404).json({ + message: `BookingReference with id: ${safeQuery.data.id} not found`, + error, + }) + ); + break; + case "DELETE": + /** + * @swagger + * /booking-references/{id}: + * delete: + * operationId: removeBookingReferenceById + * summary: Remove an existing booking reference + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: ID of the booking reference to delete + * tags: + * - booking-references + * responses: + * 201: + * description: OK, bookingReference removed successfuly + * 400: + * description: Bad request. BookingReference id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ + await prisma.bookingReference + .delete({ + where: { id: safeQuery.data.id }, }) - ); - break; - case "DELETE": - /** - * @swagger - * /booking-references/{id}: - * delete: - * operationId: removeBookingReferenceById - * summary: Remove an existing booking reference - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: ID of the booking reference to delete - * tags: - * - booking-references - * responses: - * 201: - * description: OK, bookingReference removed successfuly - * 400: - * description: Bad request. BookingReference id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ - await prisma.bookingReference - .delete({ - where: { id: safeQuery.data.id }, - }) - .then(() => - res.status(200).json({ - message: `BookingReference with id: ${safeQuery.data.id} deleted`, - }) - ) - .catch((error: Error) => - res.status(404).json({ - message: `BookingReference with id: ${safeQuery.data.id} not found`, - error, - }) - ); - break; + .then(() => + res.status(200).json({ + message: `BookingReference with id: ${safeQuery.data.id} deleted`, + }) + ) + .catch((error: Error) => + res.status(404).json({ + message: `BookingReference with id: ${safeQuery.data.id} not found`, + error, + }) + ); + break; - default: - res.status(405).json({ message: "Method not allowed" }); - break; - } - // } else res.status(401).json({ message: "Unauthorized" }); + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } + } else res.status(401).json({ message: "Unauthorized" }); } export default withMiddleware("HTTP_GET_DELETE_PATCH")( diff --git a/pages/api/users/index.ts b/pages/api/users/index.ts index 9f80a421d2..6eea24cb3b 100644 --- a/pages/api/users/index.ts +++ b/pages/api/users/index.ts @@ -40,19 +40,18 @@ async function getAllorCreateUser( message: "No Users were found", error, }); + } else if (method === "POST") { + const isAdmin = await prisma.user + .findUnique({ where: { id: userId } }) + .then((user) => user?.role === "ADMIN"); + if (!isAdmin) res.status(401).json({ message: "You are not authorized" }); + else { + const user = await prisma.user.create({ + data: schemaUserReadPublic.parse(body), + }); + res.status(201).json({ user }); + } } - // else if (method === "POST") { - // const isAdmin = await prisma.user - // .findUnique({ where: { id: userId } }) - // .then((user) => user?.role === "ADMIN"); - // if (!isAdmin) res.status(401).json({ message: "You are not authorized" }); - // else { - // const user = await prisma.user.create({ - // data: schemaUserReadPublic.parse(body), - // }); - // res.status(201).json({ user }); - // } - // } } // No POST endpoint for users for now as a regular user you're expected to signup. From dc967b7d9ebc8ff310cbe634adcb80bbf0a15a8f Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 20 May 2022 01:45:54 +0200 Subject: [PATCH 02/10] fix: hooks, event-types and booking references --- lib/helpers/verifyApiKey.ts | 14 --------- lib/validations/event-type.ts | 8 ++++- lib/validations/webhook.ts | 5 +-- pages/api/booking-references/[id].ts | 46 +++++++++------------------- 4 files changed, 25 insertions(+), 48 deletions(-) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index 2c58befc4d..c467c6ce99 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -1,22 +1,8 @@ -// import type { NextApiRequest } from "next"; import { NextMiddleware } from "next-api-middleware"; import { hashAPIKey } from "@calcom/ee/lib/api/apiKeys"; import prisma from "@calcom/prisma"; -// /** @todo figure how to use the one from `@calcom/types`fi */ -// /** @todo: remove once `@calcom/types` is updated with it.*/ -// declare module "next" { -// export interface NextApiRequest extends NextApiRequest { -// userId: number; -// body: any; -// method: string; -// query: { -// apiKey: string; -// }; -// } -// } - // Used to check if the apiKey is not expired, could be extracted if reused. but not for now. export const dateNotInPast = function (date: Date) { const now = new Date(); diff --git a/lib/validations/event-type.ts b/lib/validations/event-type.ts index aee6002089..ff11d4fcd9 100644 --- a/lib/validations/event-type.ts +++ b/lib/validations/event-type.ts @@ -87,4 +87,10 @@ export const schemaEventTypeReadPublic = EventType.pick({ description: true, locations: true, metadata: true, -}); +}).merge( + z.object({ + recurringEvent: jsonSchema.nullable(), + locations: z.array(jsonSchema).nullable(), + metadata: jsonSchema.nullable(), + }) +); diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index 5948db65eb..39b1a999a0 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -37,7 +37,8 @@ export const schemaWebhookReadPublic = Webhook.pick({ eventTypeId: true, payloadTemplate: true, eventTriggers: true, - eventType: true, - app: true, + /** @todo: find out why this breaks the api */ + // eventType: true, + // app: true, appId: true, }); diff --git a/pages/api/booking-references/[id].ts b/pages/api/booking-references/[id].ts index 47a76ea85e..f7a14056eb 100644 --- a/pages/api/booking-references/[id].ts +++ b/pages/api/booking-references/[id].ts @@ -28,20 +28,12 @@ export async function bookingReferenceById( }); if (!userWithBookings) throw new Error("User not found"); const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat(); - // console.log(userBookingIds); const bookingReferences = await prisma.bookingReference .findMany({ where: { id: { in: userBookingIds } } }) - .then((bookingReferences) => { - console.log(bookingReferences); - return bookingReferences.map((bookingReference) => bookingReference.id); - }); + .then((bookingReferences) => bookingReferences.map((bookingReference) => bookingReference.id)); - // res.status(400).json({ message: "Booking reference not found" }); - // return; - // } - if (!bookingReferences?.includes(safeQuery.data.id)) { - // if (userBookingIds.includes(safeQuery.data.id)) { - // throw new Error("BookingReference: bookingId not found"); + if (!bookingReferences?.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" }); + else { switch (method) { case "GET": /** @@ -67,26 +59,18 @@ export async function bookingReferenceById( * 404: * description: BookingReference was not found */ - // console.log(safeQuery.data.id); - const bookingReference = await prisma.bookingReference.findFirst().catch((error: Error) => { - console.log("hoerr:", error); - }); - // console.log(bookingReference); - if (!bookingReference) res.status(404).json({ message: "Booking reference not found" }); - else res.status(200).json({ booking_reference: bookingReference }); + await prisma.bookingReference + .findFirst({ where: { id: safeQuery.data.id } }) + .then((data) => schemaBookingReferenceReadPublic.parse(data)) + .then((booking_reference) => res.status(200).json({ booking_reference })) + .catch((error: Error) => { + console.log(error); + res.status(404).json({ + message: `BookingReference with id: ${safeQuery.data.id} not found`, + error, + }); + }); - // .then((data) => { - // console.log(data); - // return schemaBookingReferenceReadPublic.parse(data); - // }) - // .then((booking_reference) => res.status(200).json({ booking_reference })) - // .catch((error: Error) => { - // console.log(error); - // res.status(404).json({ - // message: `BookingReference with id: ${safeQuery.data.id} not found`, - // error, - // }); - // }); break; case "PATCH": /** @@ -192,7 +176,7 @@ export async function bookingReferenceById( res.status(405).json({ message: "Method not allowed" }); break; } - } else res.status(401).json({ message: "Unauthorized" }); + } } export default withMiddleware("HTTP_GET_DELETE_PATCH")( From d23fa4be4ed673c6d4256d7ee3dd8691e9e2a2aa Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 20 May 2022 01:47:17 +0200 Subject: [PATCH 03/10] fix: add comment to fix later any --- lib/validations/webhook.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/validations/webhook.ts b/lib/validations/webhook.ts index 39b1a999a0..e3ea709ec9 100644 --- a/lib/validations/webhook.ts +++ b/lib/validations/webhook.ts @@ -24,6 +24,7 @@ export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge(s 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(), }) From 29deb1fd3cd7afc239b91ee96fa0c2727f1279ed Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 20 May 2022 02:19:33 +0200 Subject: [PATCH 04/10] fix: add back req extend types --- lib/helpers/verifyApiKey.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index c467c6ce99..feba710c5b 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -1,8 +1,22 @@ +import type { IncomingMessage } from "http"; import { NextMiddleware } from "next-api-middleware"; import { hashAPIKey } from "@calcom/ee/lib/api/apiKeys"; import prisma from "@calcom/prisma"; +/** @todo figure how to use the one from `@calcom/types`fi */ +/** @todo: remove once `@calcom/types` is updated with it.*/ +declare module "next" { + export interface NextApiRequest extends IncomingMessage { + userId: number; + body: Body; + method: string; + query: { + apiKey: string; + }; + } +} + // Used to check if the apiKey is not expired, could be extracted if reused. but not for now. export const dateNotInPast = function (date: Date) { const now = new Date(); From b755d2bd71c433441be3c30e17e78907c702cc6e Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 20 May 2022 02:47:20 +0200 Subject: [PATCH 05/10] fix: build and validations for event-type, bring back req extension --- lib/helpers/verifyApiKey.ts | 2 +- lib/types.ts | 2 +- lib/validations/event-type.ts | 24 ++++++++++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index feba710c5b..67ad05c8ac 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -12,7 +12,7 @@ declare module "next" { body: Body; method: string; query: { - apiKey: string; + apiKey?: string; }; } } diff --git a/lib/types.ts b/lib/types.ts index 6018019abc..f61e5d7f1c 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -125,7 +125,7 @@ export type EventTypeCustomInputsResponse = BaseResponse & { event_type_custom_inputs?: Partial[]; }; // From rrule https://jakubroztocil.github.io/rrule freq -enum Frequency { +export enum Frequency { "YEARLY", "MONTHLY", "WEEKLY", diff --git a/lib/validations/event-type.ts b/lib/validations/event-type.ts index ff11d4fcd9..e3a6d83228 100644 --- a/lib/validations/event-type.ts +++ b/lib/validations/event-type.ts @@ -1,7 +1,11 @@ import { z } from "zod"; +import { AppStoreLocationType, DefaultLocationType } from "@calcom/app-store/locations"; import { _EventTypeModel as EventType } from "@calcom/prisma/zod"; +import { Frequency } from "@lib/types"; +import { timeZone } from "@lib/validations/shared/timeZone"; + import { jsonSchema } from "./shared/jsonSchema"; export const schemaEventTypeBaseBodyParams = EventType.pick({ @@ -89,8 +93,24 @@ export const schemaEventTypeReadPublic = EventType.pick({ metadata: true, }).merge( z.object({ - recurringEvent: jsonSchema.nullable(), - locations: z.array(jsonSchema).nullable(), + // { dtstart?: Date | undefined; interval?: number | undefined; count?: number | undefined; freq?: Frequency | undefined; until?: Date | undefined; tzid?: string | undefined; } | undefined' + // recurringEvent: jsonSchema.nullable(), + recurringEvent: z.object({ + dtstart: z.date().optional(), + interval: z.number().int().optional(), + count: z.number().int().optional(), + freq: z.nativeEnum(Frequency).optional(), + until: z.date().optional(), + tzid: timeZone, + }), + locations: z.array( + z.object({ + link: z.string().optional(), + address: z.string().optional(), + hostPhoneNumber: z.string().optional(), + type: z.nativeEnum(DefaultLocationType).or(z.nativeEnum(AppStoreLocationType)), + }) + ), metadata: jsonSchema.nullable(), }) ); From 4fb1c14d3d874554aa24ccabc7f11932ad9afa50 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 20 May 2022 02:57:24 +0200 Subject: [PATCH 06/10] fix: body unknown --- lib/helpers/verifyApiKey.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index 67ad05c8ac..12a92e35a5 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -9,7 +9,7 @@ import prisma from "@calcom/prisma"; declare module "next" { export interface NextApiRequest extends IncomingMessage { userId: number; - body: Body; + body: unknown; method: string; query: { apiKey?: string; From f22257977d915f4c49c96e577a1d1a2c172e9863 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 20 May 2022 03:01:47 +0200 Subject: [PATCH 07/10] fix: body any --- lib/helpers/verifyApiKey.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index 12a92e35a5..6d07d72d99 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -8,8 +8,9 @@ import prisma from "@calcom/prisma"; /** @todo: remove once `@calcom/types` is updated with it.*/ declare module "next" { export interface NextApiRequest extends IncomingMessage { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + body: any; userId: number; - body: unknown; method: string; query: { apiKey?: string; From f1cf8ba94bc3e544c95b3f1b85f1981080c881c3 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 20 May 2022 03:06:05 +0200 Subject: [PATCH 08/10] fix: query { [key: string]: string | string[]; } --- lib/helpers/verifyApiKey.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index 6d07d72d99..756fb26fe1 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -12,9 +12,7 @@ declare module "next" { body: any; userId: number; method: string; - query: { - apiKey?: string; - }; + query: { [key: string]: string | string[] }; } } From 9132bb51eb500d44dde6dd10d0668e8461e6bab4 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 20 May 2022 03:10:28 +0200 Subject: [PATCH 09/10] fix: disable create user post no role admin yet --- pages/api/users/index.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pages/api/users/index.ts b/pages/api/users/index.ts index 6eea24cb3b..9f80a421d2 100644 --- a/pages/api/users/index.ts +++ b/pages/api/users/index.ts @@ -40,18 +40,19 @@ async function getAllorCreateUser( message: "No Users were found", error, }); - } else if (method === "POST") { - const isAdmin = await prisma.user - .findUnique({ where: { id: userId } }) - .then((user) => user?.role === "ADMIN"); - if (!isAdmin) res.status(401).json({ message: "You are not authorized" }); - else { - const user = await prisma.user.create({ - data: schemaUserReadPublic.parse(body), - }); - res.status(201).json({ user }); - } } + // else if (method === "POST") { + // const isAdmin = await prisma.user + // .findUnique({ where: { id: userId } }) + // .then((user) => user?.role === "ADMIN"); + // if (!isAdmin) res.status(401).json({ message: "You are not authorized" }); + // else { + // const user = await prisma.user.create({ + // data: schemaUserReadPublic.parse(body), + // }); + // res.status(201).json({ user }); + // } + // } } // No POST endpoint for users for now as a regular user you're expected to signup. From f6746c4cf97335aaee049372d172187f7e0e0fbe Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 20 May 2022 03:15:04 +0200 Subject: [PATCH 10/10] fix: rmeove comment to fix build --- lib/helpers/verifyApiKey.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index 756fb26fe1..38fa6b44c3 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -8,11 +8,10 @@ import prisma from "@calcom/prisma"; /** @todo: remove once `@calcom/types` is updated with it.*/ declare module "next" { export interface NextApiRequest extends IncomingMessage { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - body: any; userId: number; method: string; query: { [key: string]: string | string[] }; + body: any; } }