Scheduling infrastructure for absolutely everyone.
fix: hooks, event-types and booking references
Agusti Fernandez Pardodc967b7d9ebc
diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.tsindex 2c58befc4d9..c467c6ce998 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.tsindex aee60020895..ff11d4fcd9a 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.tsindex 5948db65eb6..39b1a999a0f 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].tsindex 47a76ea85e4..f7a14056eb6 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")(