Skip to content

Scheduling infrastructure for absolutely everyone.

Adds basic CRUD endpoints for bookingReferences, Crendentials, DailyEventReferences, DestinationCalendars, EventTypeCustomInputs, Memberships, Schedules, and SelectedCalendars

Agusti Fernandez Pardo8165977ec34b
diff --git a/lib/helpers b/lib/helpers
deleted file mode 100644
index 1644c3906be..00000000000
--- a/lib/helpers
+++ /dev/null
@@ -1,35 +0,0 @@
-import prisma from "@calcom/prisma";
-
-import { User } from "@calcom/prisma/client";
-import type { NextApiRequest, NextApiResponse } from "next";
-
-type ResponseData = {
- data?: User[];
- error?: unknown;
-};
-const dateInPast = function (firstDate: Date, secondDate: Date) {
- if (firstDate.setHours(0, 0, 0, 0) <= secondDate.setHours(0, 0, 0, 0)) {
- return true;
- }
-
- return false;
-};
-const today = new Date();
-
-export default async function user(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
- const apiKey = req.query.apiKey as string;
- const apiInDb = await prisma.apiKey.findUnique({ where: { id: apiKey } });
- if (!apiInDb) throw new Error('API key not found');
- const { expiresAt } = apiInDb;
- // if (!apiInDb) res.status(400).json({ error: 'Your api key is not valid' });
- if (expiresAt && dateInPast(expiresAt, today)) {
- try {
- const data = await prisma.user.findMany();
- res.status(200).json({ data });
- } catch (error) {
- // FIXME: Add zod for validation/error handling
- res.status(400).json({ error: error });
- }
- } else res.status(400).json({ error: 'Your api key is not valid' });
-
-}
diff --git a/lib/helpers/captureError.ts b/lib/helpers/captureError.ts
new file mode 100644
index 00000000000..8835a3cb91d
--- /dev/null
+++ b/lib/helpers/captureError.ts
@@ -0,0 +1,47 @@
+import { label, NextMiddleware } from "next-api-middleware";
+import * as Sentry from "@sentry/nextjs";
+import nanoid from "nanoid";
+
+// 1 – Create middleware functions
+
+const captureErrors: NextMiddleware = async (req, res, next) => {
+ try {
+ // Catch any errors that are thrown in remaining
+ // middleware and the API route handler
+ await next();
+ } catch (err) {
+ const eventId = Sentry.captureException(err);
+
+ res.status(500);
+ res.json({ error: err });
+ }
+};
+
+const addRequestId: NextMiddleware = async (req, res, next) => {
+ // Let remaining middleware and API route execute
+ await next();
+
+ // Apply header
+ res.setHeader("X-Response-ID", nanoid());
+};
+
+// 2 – Use `label` to assemble all middleware
+
+const withMiddleware = label(
+ {
+ addRequestId,
+ sentry: captureErrors, // <-- Optionally alias middleware
+ },
+ ["sentry"] // <-- Provide a list of middleware to call automatically
+);
+
+// 3 – Define your API route handler
+
+const apiRouteHandler = async (req, res) => {
+ res.status(200);
+ res.send("Hello world!");
+};
+
+// 4 – Choose middleware to invoke for this API route
+
+export default withMiddleware("addRequestId")(apiRouteHandler);
\ No newline at end of file
diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts
new file mode 100644
index 00000000000..41dbb094d75
--- /dev/null
+++ b/lib/helpers/verifyApiKey.ts
@@ -0,0 +1,36 @@
+// https://github.com/htunnicliff/next-api-middleware
+// import prisma from "@calcom/prisma";
+
+// import { User } from "@calcom/prisma/client";
+// import type { NextApiRequest, NextApiResponse } from "next";
+
+// type ResponseData = {
+// data?: User[];
+// error?: unknown;
+// };
+// const dateInPast = function (firstDate: Date, secondDate: Date) {
+// if (firstDate.setHours(0, 0, 0, 0) <= secondDate.setHours(0, 0, 0, 0)) {
+// return true;
+// }
+
+// return false;
+// };
+// const today = new Date();
+
+// export default async function user(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+// const apiKey = req.query.apiKey as string;
+// const apiInDb = await prisma.apiKey.findUnique({ where: { id: apiKey } });
+// if (!apiInDb) throw new Error('API key not found');
+// const { expiresAt } = apiInDb;
+// // if (!apiInDb) res.status(400).json({ error: 'Your api key is not valid' });
+// if (expiresAt && dateInPast(expiresAt, today)) {
+// try {
+// const data = await prisma.user.findMany();
+// res.status(200).json({ data });
+// } catch (error) {
+// // FIXME: Add zod for validation/error handling
+// res.status(400).json({ error: error });
+// }
+// } else res.status(400).json({ error: 'Your api key is not valid' });
+
+// }
diff --git a/package.json b/package.json
index b91cd3b07fd..e70d483ecdf 100644
--- a/package.json
+++ b/package.json
@@ -32,6 +32,7 @@
},
"dependencies": {
"next": "^12.1.0",
+ "next-api-middleware": "^1.0.1",
"next-transpile-modules": "^9.0.0",
"next-validations": "^0.1.11",
"typescript": "^4.6.3",
diff --git a/pages/api/booking-references/[id]/delete.ts b/pages/api/booking-references/[id]/delete.ts
new file mode 100644
index 00000000000..13798382ba7
--- /dev/null
+++ b/pages/api/booking-references/[id]/delete.ts
@@ -0,0 +1,27 @@
+import prisma from "@calcom/prisma";
+
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+
+type ResponseData = {
+ message?: string;
+ error?: unknown;
+};
+
+export async function deleteBookingReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, method } = req;
+ const safe = await schemaQueryIdParseInt.safeParse(query);
+ if (method === "DELETE" && safe.success && safe.data) {
+ const bookingReference = await prisma.bookingReference
+ .delete({ where: { id: safe.data.id } })
+ // We only remove the bookingReference type from the database if there's an existing resource.
+ if (bookingReference) res.status(200).json({ message: `bookingReference with id: ${safe.data.id} deleted successfully` });
+ // This catches the error thrown by prisma.bookingReference.delete() if the resource is not found.
+ else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only DELETE Method allowed" });
+}
+
+export default withValidQueryIdTransformParseInt(deleteBookingReference);
diff --git a/pages/api/booking-references/[id]/edit.ts b/pages/api/booking-references/[id]/edit.ts
new file mode 100644
index 00000000000..cdfe7a739ba
--- /dev/null
+++ b/pages/api/booking-references/[id]/edit.ts
@@ -0,0 +1,32 @@
+import prisma from "@calcom/prisma";
+
+import { BookingReference } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaBookingReference, withValidBookingReference } from "@lib/validations/bookingReference";
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+type ResponseData = {
+ data?: BookingReference;
+ message?: string;
+ error?: unknown;
+};
+
+export async function editBookingReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, body, method } = req;
+ const safeQuery = await schemaQueryIdParseInt.safeParse(query);
+ const safeBody = await schemaBookingReference.safeParse(body);
+
+ if (method === "PATCH" && safeQuery.success && safeBody.success) {
+ const data = await prisma.bookingReference.update({
+ where: { id: safeQuery.data.id },
+ data: safeBody.data,
+ })
+ if (data) res.status(200).json({ data });
+ else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated` })
+
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only PATCH Method allowed for updating bookingReferences" });
+}
+
+export default withValidQueryIdTransformParseInt(withValidBookingReference(editBookingReference));
diff --git a/pages/api/booking-references/[id]/index.ts b/pages/api/booking-references/[id]/index.ts
new file mode 100644
index 00000000000..ec973f50165
--- /dev/null
+++ b/pages/api/booking-references/[id]/index.ts
@@ -0,0 +1,27 @@
+import prisma from "@calcom/prisma";
+
+import { BookingReference } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+type ResponseData = {
+ data?: BookingReference;
+ message?: string;
+ error?: unknown;
+};
+
+export async function bookingReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, method } = req;
+ const safe = await schemaQueryIdParseInt.safeParse(query);
+ if (method === "GET" && safe.success) {
+ const data = await prisma.bookingReference.findUnique({ where: { id: safe.data.id } });
+
+ if (data) res.status(200).json({ data });
+ if (!data) res.status(404).json({ message: "Event type not found" });
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only GET Method allowed" });
+}
+
+
+export default withValidQueryIdTransformParseInt(bookingReference);
diff --git a/pages/api/booking-references/index.ts b/pages/api/booking-references/index.ts
new file mode 100644
index 00000000000..460d681ca7d
--- /dev/null
+++ b/pages/api/booking-references/index.ts
@@ -0,0 +1,15 @@
+import prisma from "@calcom/prisma";
+
+import { BookingReference } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+type ResponseData = {
+ data?: BookingReference[];
+ error?: unknown;
+};
+
+export default async function bookingReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const data = await prisma.bookingReference.findMany();
+ if (data) res.status(200).json({ data });
+ else res.status(400).json({ error: "No data found" });
+}
diff --git a/pages/api/booking-references/new.ts b/pages/api/booking-references/new.ts
new file mode 100644
index 00000000000..ba21befec81
--- /dev/null
+++ b/pages/api/booking-references/new.ts
@@ -0,0 +1,26 @@
+import prisma from "@calcom/prisma";
+
+import { BookingReference } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaBookingReference, withValidBookingReference } from "@lib/validations/bookingReference";
+
+type ResponseData = {
+ data?: BookingReference;
+ message?: string;
+ error?: string;
+};
+
+async function createBookingReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { body, method } = req;
+ const safe = schemaBookingReference.safeParse(body);
+ if (method === "POST" && safe.success) {
+ await prisma.bookingReference
+ .create({ data: safe.data })
+ .then((data) => res.status(201).json({ data }))
+ .catch((error) => res.status(400).json({ message: "Could not create bookingReference type", error: error }));
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ error: "Only POST Method allowed" });
+}
+
+export default withValidBookingReference(createBookingReference);
diff --git a/pages/api/credentials/[id]/delete.ts b/pages/api/credentials/[id]/delete.ts
new file mode 100644
index 00000000000..a20e49518bf
--- /dev/null
+++ b/pages/api/credentials/[id]/delete.ts
@@ -0,0 +1,27 @@
+import prisma from "@calcom/prisma";
+
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+
+type ResponseData = {
+ message?: string;
+ error?: unknown;
+};
+
+export async function deleteCredential(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, method } = req;
+ const safe = await schemaQueryIdParseInt.safeParse(query);
+ if (method === "DELETE" && safe.success && safe.data) {
+ const credential = await prisma.credential
+ .delete({ where: { id: safe.data.id } })
+ // We only remove the credential type from the database if there's an existing resource.
+ if (credential) res.status(200).json({ message: `credential with id: ${safe.data.id} deleted successfully` });
+ // This catches the error thrown by prisma.credential.delete() if the resource is not found.
+ else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only DELETE Method allowed" });
+}
+
+export default withValidQueryIdTransformParseInt(deleteCredential);
diff --git a/pages/api/credentials/[id]/edit.ts b/pages/api/credentials/[id]/edit.ts
new file mode 100644
index 00000000000..7ee777ba596
--- /dev/null
+++ b/pages/api/credentials/[id]/edit.ts
@@ -0,0 +1,32 @@
+import prisma from "@calcom/prisma";
+
+import { Credential } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaCredential, withValidCredential } from "@lib/validations/credential";
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+type ResponseData = {
+ data?: Credential;
+ message?: string;
+ error?: unknown;
+};
+
+export async function editCredential(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, body, method } = req;
+ const safeQuery = await schemaQueryIdParseInt.safeParse(query);
+ const safeBody = await schemaCredential.safeParse(body);
+
+ if (method === "PATCH" && safeQuery.success && safeBody.success) {
+ const data = await prisma.credential.update({
+ where: { id: safeQuery.data.id },
+ data: safeBody.data,
+ })
+ if (data) res.status(200).json({ data });
+ else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
+
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only PATCH Method allowed for updating credentials" });
+}
+
+export default withValidQueryIdTransformParseInt(withValidCredential(editCredential));
diff --git a/pages/api/credentials/[id]/index.ts b/pages/api/credentials/[id]/index.ts
new file mode 100644
index 00000000000..14ca8518670
--- /dev/null
+++ b/pages/api/credentials/[id]/index.ts
@@ -0,0 +1,27 @@
+import prisma from "@calcom/prisma";
+
+import { Credential } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+type ResponseData = {
+ data?: Credential;
+ message?: string;
+ error?: unknown;
+};
+
+export async function credential(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, method } = req;
+ const safe = await schemaQueryIdParseInt.safeParse(query);
+ if (method === "GET" && safe.success) {
+ const data = await prisma.credential.findUnique({ where: { id: safe.data.id } });
+
+ if (data) res.status(200).json({ data });
+ if (!data) res.status(404).json({ message: "Event type not found" });
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only GET Method allowed" });
+}
+
+
+export default withValidQueryIdTransformParseInt(credential);
diff --git a/pages/api/credentials/index.ts b/pages/api/credentials/index.ts
new file mode 100644
index 00000000000..cb484c95dbc
--- /dev/null
+++ b/pages/api/credentials/index.ts
@@ -0,0 +1,15 @@
+import prisma from "@calcom/prisma";
+
+import { Credential } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+type ResponseData = {
+ data?: Credential[];
+ error?: unknown;
+};
+
+export default async function credential(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const data = await prisma.credential.findMany();
+ if (data) res.status(200).json({ data });
+ else res.status(400).json({ error: "No data found" });
+}
diff --git a/pages/api/credentials/new.ts b/pages/api/credentials/new.ts
new file mode 100644
index 00000000000..ad025729d85
--- /dev/null
+++ b/pages/api/credentials/new.ts
@@ -0,0 +1,26 @@
+import prisma from "@calcom/prisma";
+
+import { Credential } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaCredential, withValidCredential } from "@lib/validations/credential";
+
+type ResponseData = {
+ data?: Credential;
+ message?: string;
+ error?: string;
+};
+
+async function createCredential(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { body, method } = req;
+ const safe = schemaCredential.safeParse(body);
+ if (method === "POST" && safe.success) {
+ await prisma.credential
+ .create({ data: safe.data })
+ .then((data) => res.status(201).json({ data }))
+ .catch((error) => res.status(400).json({ message: "Could not create credential type", error: error }));
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ error: "Only POST Method allowed" });
+}
+
+export default withValidCredential(createCredential);
diff --git a/pages/api/daily-event-references/[id]/delete.ts b/pages/api/daily-event-references/[id]/delete.ts
new file mode 100644
index 00000000000..6b7a2a55416
--- /dev/null
+++ b/pages/api/daily-event-references/[id]/delete.ts
@@ -0,0 +1,27 @@
+import prisma from "@calcom/prisma";
+
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+
+type ResponseData = {
+ message?: string;
+ error?: unknown;
+};
+
+export async function deleteDailyEventReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, method } = req;
+ const safe = await schemaQueryIdParseInt.safeParse(query);
+ if (method === "DELETE" && safe.success && safe.data) {
+ const dailyEventReference = await prisma.dailyEventReference
+ .delete({ where: { id: safe.data.id } })
+ // We only remove the dailyEventReference type from the database if there's an existing resource.
+ if (dailyEventReference) res.status(200).json({ message: `dailyEventReference with id: ${safe.data.id} deleted successfully` });
+ // This catches the error thrown by prisma.dailyEventReference.delete() if the resource is not found.
+ else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only DELETE Method allowed" });
+}
+
+export default withValidQueryIdTransformParseInt(deleteDailyEventReference);
diff --git a/pages/api/daily-event-references/[id]/edit.ts b/pages/api/daily-event-references/[id]/edit.ts
new file mode 100644
index 00000000000..eb731dde8a7
--- /dev/null
+++ b/pages/api/daily-event-references/[id]/edit.ts
@@ -0,0 +1,32 @@
+import prisma from "@calcom/prisma";
+
+import { DailyEventReference } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaDailyEventReference, withValidDailyEventReference } from "@lib/validations/dailyEventReference";
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+type ResponseData = {
+ data?: DailyEventReference;
+ message?: string;
+ error?: unknown;
+};
+
+export async function editDailyEventReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, body, method } = req;
+ const safeQuery = await schemaQueryIdParseInt.safeParse(query);
+ const safeBody = await schemaDailyEventReference.safeParse(body);
+
+ if (method === "PATCH" && safeQuery.success && safeBody.success) {
+ const data = await prisma.dailyEventReference.update({
+ where: { id: safeQuery.data.id },
+ data: safeBody.data,
+ })
+ if (data) res.status(200).json({ data });
+ else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
+
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only PATCH Method allowed for updating dailyEventReferences" });
+}
+
+export default withValidQueryIdTransformParseInt(withValidDailyEventReference(editDailyEventReference));
diff --git a/pages/api/daily-event-references/[id]/index.ts b/pages/api/daily-event-references/[id]/index.ts
new file mode 100644
index 00000000000..c9b243f7072
--- /dev/null
+++ b/pages/api/daily-event-references/[id]/index.ts
@@ -0,0 +1,27 @@
+import prisma from "@calcom/prisma";
+
+import { DailyEventReference } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+type ResponseData = {
+ data?: DailyEventReference;
+ message?: string;
+ error?: unknown;
+};
+
+export async function dailyEventReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, method } = req;
+ const safe = await schemaQueryIdParseInt.safeParse(query);
+ if (method === "GET" && safe.success) {
+ const data = await prisma.dailyEventReference.findUnique({ where: { id: safe.data.id } });
+
+ if (data) res.status(200).json({ data });
+ if (!data) res.status(404).json({ message: "Event type not found" });
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only GET Method allowed" });
+}
+
+
+export default withValidQueryIdTransformParseInt(dailyEventReference);
diff --git a/pages/api/daily-event-references/index.ts b/pages/api/daily-event-references/index.ts
new file mode 100644
index 00000000000..7d25bba8f1c
--- /dev/null
+++ b/pages/api/daily-event-references/index.ts
@@ -0,0 +1,15 @@
+import prisma from "@calcom/prisma";
+
+import { DailyEventReference } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+type ResponseData = {
+ data?: DailyEventReference[];
+ error?: unknown;
+};
+
+export default async function dailyEventReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const data = await prisma.dailyEventReference.findMany();
+ if (data) res.status(200).json({ data });
+ else res.status(400).json({ error: "No data found" });
+}
diff --git a/pages/api/daily-event-references/new.ts b/pages/api/daily-event-references/new.ts
new file mode 100644
index 00000000000..c508b37e087
--- /dev/null
+++ b/pages/api/daily-event-references/new.ts
@@ -0,0 +1,26 @@
+import prisma from "@calcom/prisma";
+
+import { DailyEventReference } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaDailyEventReference, withValidDailyEventReference } from "@lib/validations/dailyEventReference";
+
+type ResponseData = {
+ data?: DailyEventReference;
+ message?: string;
+ error?: string;
+};
+
+async function createDailyEventReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { body, method } = req;
+ const safe = schemaDailyEventReference.safeParse(body);
+ if (method === "POST" && safe.success) {
+ await prisma.dailyEventReference
+ .create({ data: safe.data })
+ .then((data) => res.status(201).json({ data }))
+ .catch((error) => res.status(400).json({ message: "Could not create dailyEventReference type", error: error }));
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ error: "Only POST Method allowed" });
+}
+
+export default withValidDailyEventReference(createDailyEventReference);
diff --git a/pages/api/destination-calendars/[id]/delete.ts b/pages/api/destination-calendars/[id]/delete.ts
new file mode 100644
index 00000000000..246d5a58ebd
--- /dev/null
+++ b/pages/api/destination-calendars/[id]/delete.ts
@@ -0,0 +1,27 @@
+import prisma from "@calcom/prisma";
+
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+
+type ResponseData = {
+ message?: string;
+ error?: unknown;
+};
+
+export async function deleteDestinationCalendar(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, method } = req;
+ const safe = await schemaQueryIdParseInt.safeParse(query);
+ if (method === "DELETE" && safe.success && safe.data) {
+ const destinationCalendar = await prisma.destinationCalendar
+ .delete({ where: { id: safe.data.id } })
+ // We only remove the destinationCalendar type from the database if there's an existing resource.
+ if (destinationCalendar) res.status(200).json({ message: `destinationCalendar with id: ${safe.data.id} deleted successfully` });
+ // This catches the error thrown by prisma.destinationCalendar.delete() if the resource is not found.
+ else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only DELETE Method allowed" });
+}
+
+export default withValidQueryIdTransformParseInt(deleteDestinationCalendar);
diff --git a/pages/api/destination-calendars/[id]/edit.ts b/pages/api/destination-calendars/[id]/edit.ts
new file mode 100644
index 00000000000..5cc11fa10db
--- /dev/null
+++ b/pages/api/destination-calendars/[id]/edit.ts
@@ -0,0 +1,32 @@
+import prisma from "@calcom/prisma";
+
+import { DestinationCalendar } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaDestinationCalendar, withValidDestinationCalendar } from "@lib/validations/destinationCalendar";
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+type ResponseData = {
+ data?: DestinationCalendar;
+ message?: string;
+ error?: unknown;
+};
+
+export async function editDestinationCalendar(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, body, method } = req;
+ const safeQuery = await schemaQueryIdParseInt.safeParse(query);
+ const safeBody = await schemaDestinationCalendar.safeParse(body);
+
+ if (method === "PATCH" && safeQuery.success && safeBody.success) {
+ const data = await prisma.destinationCalendar.update({
+ where: { id: safeQuery.data.id },
+ data: safeBody.data,
+ })
+ if (data) res.status(200).json({ data });
+ else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
+
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only PATCH Method allowed for updating destinationCalendars" });
+}
+
+export default withValidQueryIdTransformParseInt(withValidDestinationCalendar(editDestinationCalendar));
diff --git a/pages/api/destination-calendars/[id]/index.ts b/pages/api/destination-calendars/[id]/index.ts
new file mode 100644
index 00000000000..95a14093720
--- /dev/null
+++ b/pages/api/destination-calendars/[id]/index.ts
@@ -0,0 +1,27 @@
+import prisma from "@calcom/prisma";
+
+import { DestinationCalendar } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+type ResponseData = {
+ data?: DestinationCalendar;
+ message?: string;
+ error?: unknown;
+};
+
+export async function destinationCalendar(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, method } = req;
+ const safe = await schemaQueryIdParseInt.safeParse(query);
+ if (method === "GET" && safe.success) {
+ const data = await prisma.destinationCalendar.findUnique({ where: { id: safe.data.id } });
+
+ if (data) res.status(200).json({ data });
+ if (!data) res.status(404).json({ message: "Event type not found" });
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only GET Method allowed" });
+}
+
+
+export default withValidQueryIdTransformParseInt(destinationCalendar);
diff --git a/pages/api/destination-calendars/index.ts b/pages/api/destination-calendars/index.ts
new file mode 100644
index 00000000000..3877dbc08aa
--- /dev/null
+++ b/pages/api/destination-calendars/index.ts
@@ -0,0 +1,15 @@
+import prisma from "@calcom/prisma";
+
+import { DestinationCalendar } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+type ResponseData = {
+ data?: DestinationCalendar[];
+ error?: unknown;
+};
+
+export default async function destinationCalendar(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const data = await prisma.destinationCalendar.findMany();
+ if (data) res.status(200).json({ data });
+ else res.status(400).json({ error: "No data found" });
+}
diff --git a/pages/api/destination-calendars/new.ts b/pages/api/destination-calendars/new.ts
new file mode 100644
index 00000000000..514217401c4
--- /dev/null
+++ b/pages/api/destination-calendars/new.ts
@@ -0,0 +1,26 @@
+import prisma from "@calcom/prisma";
+
+import { DestinationCalendar } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaDestinationCalendar, withValidDestinationCalendar } from "@lib/validations/destinationCalendar";
+
+type ResponseData = {
+ data?: DestinationCalendar;
+ message?: string;
+ error?: string;
+};
+
+async function createDestinationCalendar(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { body, method } = req;
+ const safe = schemaDestinationCalendar.safeParse(body);
+ if (method === "POST" && safe.success) {
+ await prisma.destinationCalendar
+ .create({ data: safe.data })
+ .then((data) => res.status(201).json({ data }))
+ .catch((error) => res.status(400).json({ message: "Could not create destinationCalendar type", error: error }));
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ error: "Only POST Method allowed" });
+}
+
+export default withValidDestinationCalendar(createDestinationCalendar);
diff --git a/pages/api/event-type-custom-inputs/[id]/delete.ts b/pages/api/event-type-custom-inputs/[id]/delete.ts
new file mode 100644
index 00000000000..d4e8431f51b
--- /dev/null
+++ b/pages/api/event-type-custom-inputs/[id]/delete.ts
@@ -0,0 +1,27 @@
+import prisma from "@calcom/prisma";
+
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+
+type ResponseData = {
+ message?: string;
+ error?: unknown;
+};
+
+export async function deleteEventTypeCustomInput(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, method } = req;
+ const safe = await schemaQueryIdParseInt.safeParse(query);
+ if (method === "DELETE" && safe.success && safe.data) {
+ const eventTypeCustomInput = await prisma.eventTypeCustomInput
+ .delete({ where: { id: safe.data.id } })
+ // We only remove the eventTypeCustomInput type from the database if there's an existing resource.
+ if (eventTypeCustomInput) res.status(200).json({ message: `eventTypeCustomInput with id: ${safe.data.id} deleted successfully` });
+ // This catches the error thrown by prisma.eventTypeCustomInput.delete() if the resource is not found.
+ else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only DELETE Method allowed" });
+}
+
+export default withValidQueryIdTransformParseInt(deleteEventTypeCustomInput);
diff --git a/pages/api/event-type-custom-inputs/[id]/edit.ts b/pages/api/event-type-custom-inputs/[id]/edit.ts
new file mode 100644
index 00000000000..fcb650c906c
--- /dev/null
+++ b/pages/api/event-type-custom-inputs/[id]/edit.ts
@@ -0,0 +1,32 @@
+import prisma from "@calcom/prisma";
+
+import { EventTypeCustomInput } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaEventTypeCustomInput, withValidEventTypeCustomInput } from "@lib/validations/eventTypeCustomInput";
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+type ResponseData = {
+ data?: EventTypeCustomInput;
+ message?: string;
+ error?: unknown;
+};
+
+export async function editEventTypeCustomInput(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, body, method } = req;
+ const safeQuery = await schemaQueryIdParseInt.safeParse(query);
+ const safeBody = await schemaEventTypeCustomInput.safeParse(body);
+
+ if (method === "PATCH" && safeQuery.success && safeBody.success) {
+ const data = await prisma.eventTypeCustomInput.update({
+ where: { id: safeQuery.data.id },
+ data: safeBody.data,
+ })
+ if (data) res.status(200).json({ data });
+ else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
+
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only PATCH Method allowed for updating eventTypeCustomInputs" });
+}
+
+export default withValidQueryIdTransformParseInt(withValidEventTypeCustomInput(editEventTypeCustomInput));
diff --git a/pages/api/event-type-custom-inputs/[id]/index.ts b/pages/api/event-type-custom-inputs/[id]/index.ts
new file mode 100644
index 00000000000..3b7a926dcd5
--- /dev/null
+++ b/pages/api/event-type-custom-inputs/[id]/index.ts
@@ -0,0 +1,27 @@
+import prisma from "@calcom/prisma";
+
+import { EventTypeCustomInput } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+type ResponseData = {
+ data?: EventTypeCustomInput;
+ message?: string;
+ error?: unknown;
+};
+
+export async function eventTypeCustomInput(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, method } = req;
+ const safe = await schemaQueryIdParseInt.safeParse(query);
+ if (method === "GET" && safe.success) {
+ const data = await prisma.eventTypeCustomInput.findUnique({ where: { id: safe.data.id } });
+
+ if (data) res.status(200).json({ data });
+ if (!data) res.status(404).json({ message: "Event type not found" });
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only GET Method allowed" });
+}
+
+
+export default withValidQueryIdTransformParseInt(eventTypeCustomInput);
diff --git a/pages/api/event-type-custom-inputs/index.ts b/pages/api/event-type-custom-inputs/index.ts
new file mode 100644
index 00000000000..733539064e2
--- /dev/null
+++ b/pages/api/event-type-custom-inputs/index.ts
@@ -0,0 +1,15 @@
+import prisma from "@calcom/prisma";
+
+import { EventTypeCustomInput } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+type ResponseData = {
+ data?: EventTypeCustomInput[];
+ error?: unknown;
+};
+
+export default async function eventTypeCustomInput(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const data = await prisma.eventTypeCustomInput.findMany();
+ if (data) res.status(200).json({ data });
+ else res.status(400).json({ error: "No data found" });
+}
diff --git a/pages/api/event-type-custom-inputs/new.ts b/pages/api/event-type-custom-inputs/new.ts
new file mode 100644
index 00000000000..abdb4100701
--- /dev/null
+++ b/pages/api/event-type-custom-inputs/new.ts
@@ -0,0 +1,26 @@
+import prisma from "@calcom/prisma";
+
+import { EventTypeCustomInput } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaEventTypeCustomInput, withValidEventTypeCustomInput } from "@lib/validations/eventTypeCustomInput";
+
+type ResponseData = {
+ data?: EventTypeCustomInput;
+ message?: string;
+ error?: string;
+};
+
+async function createEventTypeCustomInput(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { body, method } = req;
+ const safe = schemaEventTypeCustomInput.safeParse(body);
+ if (method === "POST" && safe.success) {
+ await prisma.eventTypeCustomInput
+ .create({ data: safe.data })
+ .then((data) => res.status(201).json({ data }))
+ .catch((error) => res.status(400).json({ message: "Could not create eventTypeCustomInput type", error: error }));
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ error: "Only POST Method allowed" });
+}
+
+export default withValidEventTypeCustomInput(createEventTypeCustomInput);
diff --git a/pages/api/memberships/[id]/delete.ts b/pages/api/memberships/[id]/delete.ts
new file mode 100644
index 00000000000..54c4fc96596
--- /dev/null
+++ b/pages/api/memberships/[id]/delete.ts
@@ -0,0 +1,27 @@
+import prisma from "@calcom/prisma";
+
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+
+type ResponseData = {
+ message?: string;
+ error?: unknown;
+};
+
+export async function deleteMembership(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, method } = req;
+ const safe = await schemaQueryIdParseInt.safeParse(query);
+ if (method === "DELETE" && safe.success && safe.data) {
+ const membership = await prisma.membership
+ .delete({ where: { id: safe.data.id } })
+ // We only remove the membership type from the database if there's an existing resource.
+ if (membership) res.status(200).json({ message: `membership with id: ${safe.data.id} deleted successfully` });
+ // This catches the error thrown by prisma.membership.delete() if the resource is not found.
+ else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only DELETE Method allowed" });
+}
+
+export default withValidQueryIdTransformParseInt(deleteMembership);
diff --git a/pages/api/memberships/[id]/edit.ts b/pages/api/memberships/[id]/edit.ts
new file mode 100644
index 00000000000..63cdba3c0a6
--- /dev/null
+++ b/pages/api/memberships/[id]/edit.ts
@@ -0,0 +1,32 @@
+import prisma from "@calcom/prisma";
+
+import { Membership } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaMembership, withValidMembership } from "@lib/validations/membership";
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+type ResponseData = {
+ data?: Membership;
+ message?: string;
+ error?: unknown;
+};
+
+export async function editMembership(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, body, method } = req;
+ const safeQuery = await schemaQueryIdParseInt.safeParse(query);
+ const safeBody = await schemaMembership.safeParse(body);
+
+ if (method === "PATCH" && safeQuery.success && safeBody.success) {
+ const data = await prisma.membership.update({
+ where: { id: safeQuery.data.id },
+ data: safeBody.data,
+ })
+ if (data) res.status(200).json({ data });
+ else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
+
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only PATCH Method allowed for updating memberships" });
+}
+
+export default withValidQueryIdTransformParseInt(withValidMembership(editMembership));
diff --git a/pages/api/memberships/[id]/index.ts b/pages/api/memberships/[id]/index.ts
new file mode 100644
index 00000000000..7f56aa3889c
--- /dev/null
+++ b/pages/api/memberships/[id]/index.ts
@@ -0,0 +1,27 @@
+import prisma from "@calcom/prisma";
+
+import { Membership } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+type ResponseData = {
+ data?: Membership;
+ message?: string;
+ error?: unknown;
+};
+
+export async function membership(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, method } = req;
+ const safe = await schemaQueryIdParseInt.safeParse(query);
+ if (method === "GET" && safe.success) {
+ const data = await prisma.membership.findUnique({ where: { id: safe.data.id } });
+
+ if (data) res.status(200).json({ data });
+ if (!data) res.status(404).json({ message: "Event type not found" });
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only GET Method allowed" });
+}
+
+
+export default withValidQueryIdTransformParseInt(membership);
diff --git a/pages/api/memberships/index.ts b/pages/api/memberships/index.ts
new file mode 100644
index 00000000000..c993dd2134c
--- /dev/null
+++ b/pages/api/memberships/index.ts
@@ -0,0 +1,15 @@
+import prisma from "@calcom/prisma";
+
+import { Membership } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+type ResponseData = {
+ data?: Membership[];
+ error?: unknown;
+};
+
+export default async function membership(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const data = await prisma.membership.findMany();
+ if (data) res.status(200).json({ data });
+ else res.status(400).json({ error: "No data found" });
+}
diff --git a/pages/api/memberships/new.ts b/pages/api/memberships/new.ts
new file mode 100644
index 00000000000..c19365f3a05
--- /dev/null
+++ b/pages/api/memberships/new.ts
@@ -0,0 +1,26 @@
+import prisma from "@calcom/prisma";
+
+import { Membership } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaMembership, withValidMembership } from "@lib/validations/membership";
+
+type ResponseData = {
+ data?: Membership;
+ message?: string;
+ error?: string;
+};
+
+async function createMembership(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { body, method } = req;
+ const safe = schemaMembership.safeParse(body);
+ if (method === "POST" && safe.success) {
+ await prisma.membership
+ .create({ data: safe.data })
+ .then((data) => res.status(201).json({ data }))
+ .catch((error) => res.status(400).json({ message: "Could not create membership type", error: error }));
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ error: "Only POST Method allowed" });
+}
+
+export default withValidMembership(createMembership);
diff --git a/pages/api/schedules/[id]/delete.ts b/pages/api/schedules/[id]/delete.ts
new file mode 100644
index 00000000000..0dcaf7910a3
--- /dev/null
+++ b/pages/api/schedules/[id]/delete.ts
@@ -0,0 +1,27 @@
+import prisma from "@calcom/prisma";
+
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+
+type ResponseData = {
+ message?: string;
+ error?: unknown;
+};
+
+export async function deleteSchedule(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, method } = req;
+ const safe = await schemaQueryIdParseInt.safeParse(query);
+ if (method === "DELETE" && safe.success && safe.data) {
+ const schedule = await prisma.schedule
+ .delete({ where: { id: safe.data.id } })
+ // We only remove the schedule type from the database if there's an existing resource.
+ if (schedule) res.status(200).json({ message: `schedule with id: ${safe.data.id} deleted successfully` });
+ // This catches the error thrown by prisma.schedule.delete() if the resource is not found.
+ else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only DELETE Method allowed" });
+}
+
+export default withValidQueryIdTransformParseInt(deleteSchedule);
diff --git a/pages/api/schedules/[id]/edit.ts b/pages/api/schedules/[id]/edit.ts
new file mode 100644
index 00000000000..5b207636cc3
--- /dev/null
+++ b/pages/api/schedules/[id]/edit.ts
@@ -0,0 +1,32 @@
+import prisma from "@calcom/prisma";
+
+import { Schedule } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaSchedule, withValidSchedule } from "@lib/validations/schedule";
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+type ResponseData = {
+ data?: Schedule;
+ message?: string;
+ error?: unknown;
+};
+
+export async function editSchedule(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, body, method } = req;
+ const safeQuery = await schemaQueryIdParseInt.safeParse(query);
+ const safeBody = await schemaSchedule.safeParse(body);
+
+ if (method === "PATCH" && safeQuery.success && safeBody.success) {
+ const data = await prisma.schedule.update({
+ where: { id: safeQuery.data.id },
+ data: safeBody.data,
+ })
+ if (data) res.status(200).json({ data });
+ else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
+
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only PATCH Method allowed for updating schedules" });
+}
+
+export default withValidQueryIdTransformParseInt(withValidSchedule(editSchedule));
diff --git a/pages/api/schedules/[id]/index.ts b/pages/api/schedules/[id]/index.ts
new file mode 100644
index 00000000000..f6d3621a809
--- /dev/null
+++ b/pages/api/schedules/[id]/index.ts
@@ -0,0 +1,27 @@
+import prisma from "@calcom/prisma";
+
+import { Schedule } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+type ResponseData = {
+ data?: Schedule;
+ message?: string;
+ error?: unknown;
+};
+
+export async function schedule(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, method } = req;
+ const safe = await schemaQueryIdParseInt.safeParse(query);
+ if (method === "GET" && safe.success) {
+ const data = await prisma.schedule.findUnique({ where: { id: safe.data.id } });
+
+ if (data) res.status(200).json({ data });
+ if (!data) res.status(404).json({ message: "Event type not found" });
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only GET Method allowed" });
+}
+
+
+export default withValidQueryIdTransformParseInt(schedule);
diff --git a/pages/api/schedules/index.ts b/pages/api/schedules/index.ts
new file mode 100644
index 00000000000..3892a461b5b
--- /dev/null
+++ b/pages/api/schedules/index.ts
@@ -0,0 +1,15 @@
+import prisma from "@calcom/prisma";
+
+import { Schedule } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+type ResponseData = {
+ data?: Schedule[];
+ error?: unknown;
+};
+
+export default async function schedule(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const data = await prisma.schedule.findMany();
+ if (data) res.status(200).json({ data });
+ else res.status(400).json({ error: "No data found" });
+}
diff --git a/pages/api/schedules/new.ts b/pages/api/schedules/new.ts
new file mode 100644
index 00000000000..ad3e1f90bf0
--- /dev/null
+++ b/pages/api/schedules/new.ts
@@ -0,0 +1,26 @@
+import prisma from "@calcom/prisma";
+
+import { Schedule } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaSchedule, withValidSchedule } from "@lib/validations/schedule";
+
+type ResponseData = {
+ data?: Schedule;
+ message?: string;
+ error?: string;
+};
+
+async function createSchedule(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { body, method } = req;
+ const safe = schemaSchedule.safeParse(body);
+ if (method === "POST" && safe.success) {
+ await prisma.schedule
+ .create({ data: safe.data })
+ .then((data) => res.status(201).json({ data }))
+ .catch((error) => res.status(400).json({ message: "Could not create schedule type", error: error }));
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ error: "Only POST Method allowed" });
+}
+
+export default withValidSchedule(createSchedule);
diff --git a/pages/api/selected-calendars/[id]/delete.ts b/pages/api/selected-calendars/[id]/delete.ts
new file mode 100644
index 00000000000..06a0c5a156e
--- /dev/null
+++ b/pages/api/selected-calendars/[id]/delete.ts
@@ -0,0 +1,27 @@
+import prisma from "@calcom/prisma";
+
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+
+type ResponseData = {
+ message?: string;
+ error?: unknown;
+};
+
+export async function deleteSelectedCalendar(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, method } = req;
+ const safe = await schemaQueryIdParseInt.safeParse(query);
+ if (method === "DELETE" && safe.success && safe.data) {
+ const selectedCalendar = await prisma.selectedCalendar
+ .delete({ where: { id: safe.data.id } })
+ // We only remove the selectedCalendar type from the database if there's an existing resource.
+ if (selectedCalendar) res.status(200).json({ message: `selectedCalendar with id: ${safe.data.id} deleted successfully` });
+ // This catches the error thrown by prisma.selectedCalendar.delete() if the resource is not found.
+ else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only DELETE Method allowed" });
+}
+
+export default withValidQueryIdTransformParseInt(deleteSelectedCalendar);
diff --git a/pages/api/selected-calendars/[id]/edit.ts b/pages/api/selected-calendars/[id]/edit.ts
new file mode 100644
index 00000000000..c53dc4222ed
--- /dev/null
+++ b/pages/api/selected-calendars/[id]/edit.ts
@@ -0,0 +1,32 @@
+import prisma from "@calcom/prisma";
+
+import { SelectedCalendar } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaSelectedCalendar, withValidSelectedCalendar } from "@lib/validations/selectedCalendar";
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+type ResponseData = {
+ data?: SelectedCalendar;
+ message?: string;
+ error?: unknown;
+};
+
+export async function editSelectedCalendar(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, body, method } = req;
+ const safeQuery = await schemaQueryIdParseInt.safeParse(query);
+ const safeBody = await schemaSelectedCalendar.safeParse(body);
+
+ if (method === "PATCH" && safeQuery.success && safeBody.success) {
+ const data = await prisma.selectedCalendar.update({
+ where: { id: safeQuery.data.id },
+ data: safeBody.data,
+ })
+ if (data) res.status(200).json({ data });
+ else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
+
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only PATCH Method allowed for updating selectedCalendars" });
+}
+
+export default withValidQueryIdTransformParseInt(withValidSelectedCalendar(editSelectedCalendar));
diff --git a/pages/api/selected-calendars/[id]/index.ts b/pages/api/selected-calendars/[id]/index.ts
new file mode 100644
index 00000000000..d89fb31398e
--- /dev/null
+++ b/pages/api/selected-calendars/[id]/index.ts
@@ -0,0 +1,27 @@
+import prisma from "@calcom/prisma";
+
+import { SelectedCalendar } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
+
+type ResponseData = {
+ data?: SelectedCalendar;
+ message?: string;
+ error?: unknown;
+};
+
+export async function selectedCalendar(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { query, method } = req;
+ const safe = await schemaQueryIdParseInt.safeParse(query);
+ if (method === "GET" && safe.success) {
+ const data = await prisma.selectedCalendar.findUnique({ where: { id: safe.data.id } });
+
+ if (data) res.status(200).json({ data });
+ if (!data) res.status(404).json({ message: "Event type not found" });
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ message: "Only GET Method allowed" });
+}
+
+
+export default withValidQueryIdTransformParseInt(selectedCalendar);
diff --git a/pages/api/selected-calendars/index.ts b/pages/api/selected-calendars/index.ts
new file mode 100644
index 00000000000..d6a29e3dd34
--- /dev/null
+++ b/pages/api/selected-calendars/index.ts
@@ -0,0 +1,15 @@
+import prisma from "@calcom/prisma";
+
+import { SelectedCalendar } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+type ResponseData = {
+ data?: SelectedCalendar[];
+ error?: unknown;
+};
+
+export default async function selectedCalendar(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const data = await prisma.selectedCalendar.findMany();
+ if (data) res.status(200).json({ data });
+ else res.status(400).json({ error: "No data found" });
+}
diff --git a/pages/api/selected-calendars/new.ts b/pages/api/selected-calendars/new.ts
new file mode 100644
index 00000000000..649e276a5eb
--- /dev/null
+++ b/pages/api/selected-calendars/new.ts
@@ -0,0 +1,26 @@
+import prisma from "@calcom/prisma";
+
+import { SelectedCalendar } from "@calcom/prisma/client";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { schemaSelectedCalendar, withValidSelectedCalendar } from "@lib/validations/selectedCalendar";
+
+type ResponseData = {
+ data?: SelectedCalendar;
+ message?: string;
+ error?: string;
+};
+
+async function createSelectedCalendar(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
+ const { body, method } = req;
+ const safe = schemaSelectedCalendar.safeParse(body);
+ if (method === "POST" && safe.success) {
+ await prisma.selectedCalendar
+ .create({ data: safe.data })
+ .then((data) => res.status(201).json({ data }))
+ .catch((error) => res.status(400).json({ message: "Could not create selectedCalendar type", error: error }));
+ // Reject any other HTTP method than POST
+ } else res.status(405).json({ error: "Only POST Method allowed" });
+}
+
+export default withValidSelectedCalendar(createSelectedCalendar);
diff --git a/pages/api/users/[id]/edit.ts b/pages/api/users/[id]/edit.ts
index 1e5780fc357..cba92305438 100644
--- a/pages/api/users/[id]/edit.ts
+++ b/pages/api/users/[id]/edit.ts
@@ -17,21 +17,16 @@ export async function editUser(req: NextApiRequest, res: NextApiResponse<Respons
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
const safeBody = await schemaUser.safeParse(body);
- if (method === "PATCH") {
- if (safeQuery.success && safeBody.success) {
- await prisma.user.update({
+ if (method === "PATCH" && safeQuery.success && safeBody.success) {
+ const data = await prisma.user.update({
where: { id: safeQuery.data.id },
data: safeBody.data,
- }).then(user => {
- res.status(200).json({ data: user });
- }).catch(error => {
- res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
- });
- }
- } else {
+ })
+ if (data) res.status(200).json({ data });
+ else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
+
// Reject any other HTTP method than POST
- res.status(405).json({ message: "Only PATCH Method allowed for updating users" });
- }
+ } else res.status(405).json({ message: "Only PATCH Method allowed for updating users" });
}
export default withValidQueryIdTransformParseInt(withValidUser(editUser));
diff --git a/pages/api/users/[id]/index.ts b/pages/api/users/[id]/index.ts
index 8852ad6e6f0..61be86fe7ce 100644
--- a/pages/api/users/[id]/index.ts
+++ b/pages/api/users/[id]/index.ts
@@ -15,14 +15,12 @@ export async function user(req: NextApiRequest, res: NextApiResponse<ResponseDat
const { query, method } = req;
const safe = await schemaQueryIdParseInt.safeParse(query);
if (method === "GET" && safe.success) {
- const user = await prisma.user.findUnique({ where: { id: safe.data.id } });
+ const data = await prisma.user.findUnique({ where: { id: safe.data.id } });
- if (user) res.status(200).json({ data: user });
- if (!user) res.status(404).json({ message: "Event type not found" });
- } else {
+ if (data) res.status(200).json({ data });
+ if (!data) res.status(404).json({ message: "Event type not found" });
// Reject any other HTTP method than POST
- res.status(405).json({ message: "Only GET Method allowed" });
- }
+ } else res.status(405).json({ message: "Only GET Method allowed" });
}
diff --git a/pages/api/users/index.ts b/pages/api/users/index.ts
index 33afee9f5ed..8f83378eada 100644
--- a/pages/api/users/index.ts
+++ b/pages/api/users/index.ts
@@ -9,11 +9,7 @@ type ResponseData = {
};
export default async function user(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
- try {
- const users = await prisma.user.findMany();
- res.status(200).json({ data: { ...users } });
- } catch (error) {
- // FIXME: Add zod for validation/error handling
- res.status(400).json({ error: error });
- }
+ const data = await prisma.user.findMany();
+ if (data) res.status(200).json({ data });
+ else res.status(400).json({ error: "No data found" });
}
diff --git a/pages/api/users/new.ts b/pages/api/users/new.ts
index ae298fdfb3f..7f319e62d9d 100644
--- a/pages/api/users/new.ts
+++ b/pages/api/users/new.ts
@@ -17,7 +17,7 @@ async function createUser(req: NextApiRequest, res: NextApiResponse<ResponseData
if (method === "POST" && safe.success) {
await prisma.user
.create({ data: safe.data })
- .then((user) => res.status(201).json({ data: user }))
+ .then((data) => res.status(201).json({ data }))
.catch((error) => res.status(400).json({ message: "Could not create user type", error: error }));
// Reject any other HTTP method than POST
} else res.status(405).json({ error: "Only POST Method allowed" });