Scheduling infrastructure for absolutely everyone.
feat: all resources endpoints for get all and new unified
Agusti Fernandez Pardo0bda98867665
diff --git a/pages/api/attendees/[id].ts b/pages/api/attendees/[id].tsindex 6044c6cc742..093579a7990 100644--- a/pages/api/attendees/[id].ts+++ b/pages/api/attendees/[id].ts@@ -12,7 +12,7 @@ import {/*** @swagger- * /api/attendees/{id}:+ * /v1/attendees/{id}:* get:* summary: Get an attendee by ID* parameters:diff --git a/pages/api/attendees/index.ts b/pages/api/attendees/index.tsindex d9f74293253..509907bb8d5 100644--- a/pages/api/attendees/index.ts+++ b/pages/api/attendees/index.ts@@ -9,7 +9,7 @@ import { schemaAttendeeBodyParams, schemaAttendeePublic, withValidAttendee } fro/*** @swagger- * /api/attendees:+ * /v1/attendees:* get:* summary: Get all attendees* tags:diff --git a/pages/api/availabilities/[id].ts b/pages/api/availabilities/[id].tsindex 1c126ff2c2c..34bab030080 100644--- a/pages/api/availabilities/[id].ts+++ b/pages/api/availabilities/[id].ts@@ -12,7 +12,7 @@ import {/*** @swagger- * /api/availabilities/{id}:+ * /v1/availabilities/{id}:* get:* summary: Get an availability by ID* parameters:diff --git a/pages/api/availabilities/index.ts b/pages/api/availabilities/index.tsindex d0408a32aa5..9778bfdbfa5 100644--- a/pages/api/availabilities/index.ts+++ b/pages/api/availabilities/index.ts@@ -8,7 +8,7 @@ import { schemaAvailabilityBodyParams, schemaAvailabilityPublic } from "@lib/val/*** @swagger- * /api/availabilities:+ * /v1/availabilities:* get:* summary: Get all availabilities* tags:diff --git a/pages/api/booking-references/[id].ts b/pages/api/booking-references/[id].tsindex 659c48f46df..2d48aa74130 100644--- a/pages/api/booking-references/[id].ts+++ b/pages/api/booking-references/[id].ts@@ -15,7 +15,7 @@ import {/*** @swagger- * /api/booking-references/{id}:+ * /v1/booking-references/{id}:* get:* summary: Get a daily event reference by ID* parameters:@@ -90,6 +90,7 @@ export async function bookingReferenceById(const safeQuery = schemaQueryIdParseInt.safeParse(query);const safeBody = schemaBookingReferenceBodyParams.safeParse(body);if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);+ // FIXME: Allow only userId owner of booking ref to edit itswitch (method) {case "GET":diff --git a/pages/api/booking-references/index.ts b/pages/api/booking-references/index.tsindex df12d1c882f..0ca58c2f8a3 100644--- a/pages/api/booking-references/index.ts+++ b/pages/api/booking-references/index.ts@@ -11,7 +11,7 @@ import {/*** @swagger- * /api/booking-references:+ * /v1/booking-references:* get:* summary: Get all booking references* tags:diff --git a/pages/api/bookings/[id].ts b/pages/api/bookings/[id].tsindex f3104fc44e6..45f24774e62 100644--- a/pages/api/bookings/[id].ts+++ b/pages/api/bookings/[id].ts@@ -12,7 +12,7 @@ import {/*** @swagger- * /api/bookings/{id}:+ * /v1/bookings/{id}:* get:* summary: Get a booking by ID* parameters:@@ -84,7 +84,7 @@ export async function bookingById(req: NextApiRequest, res: NextApiResponse<Bookconst safeQuery = schemaQueryIdParseInt.safeParse(query);const safeBody = schemaBookingBodyParams.safeParse(body);if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);-+ // FIXME: Allow only userId owner of booking to edit itswitch (method) {case "GET":await prisma.bookingdiff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.tsindex dabf90f245e..fd5f8b19aff 100644--- a/pages/api/bookings/index.ts+++ b/pages/api/bookings/index.ts@@ -8,7 +8,7 @@ import { schemaBookingBodyParams, schemaBookingPublic, withValidBooking } from "/*** @swagger- * /api/bookings:+ * /v1/bookings:* get:* summary: Get all bookings* tags:@@ -38,6 +38,8 @@ async function createOrlistAllBookings(res: NextApiResponse<BookingsResponse | BookingResponse>) {const { method } = req;+ // FIXME: List only bookings owner by userId+if (method === "GET") {const data = await prisma.booking.findMany();const bookings = data.map((booking) => schemaBookingPublic.parse(booking));diff --git a/pages/api/credentials/[id].ts b/pages/api/credentials/[id].tsindex 16c60007a47..bb82d0f0198 100644--- a/pages/api/credentials/[id].ts+++ b/pages/api/credentials/[id].ts@@ -12,7 +12,7 @@ import {/*** @swagger- * /api/credentials/{id}:+ * /v1/credentials/{id}:* get:* summary: Get a credential by ID* parameters:@@ -89,8 +89,8 @@ export async function credentialById(req: NextApiRequest, res: NextApiResponse<Ccase "GET":await prisma.credential.findUnique({ where: { id: safeQuery.data.id } })- .then((credential) => schemaCredentialPublic.parse(credential))- .then((data) => res.status(200).json({ data }))+ .then((data) => schemaCredentialPublic.parse(data))+ .then((credential) => res.status(200).json({ credential })).catch((error: Error) =>res.status(404).json({ message: `Credential with id: ${safeQuery.data.id} not found`, error }));@@ -103,8 +103,8 @@ export async function credentialById(req: NextApiRequest, res: NextApiResponse<Cwhere: { id: safeQuery.data.id },data: safeBody.data,})- .then((credential) => schemaCredentialPublic.parse(credential))- .then((data) => res.status(200).json({ data }))+ .then((data) => schemaCredentialPublic.parse(data))+ .then((credential) => res.status(200).json({ credential })).catch((error: Error) =>res.status(404).json({ message: `Credential with id: ${safeQuery.data.id} not found`, error }));diff --git a/pages/api/credentials/index.ts b/pages/api/credentials/index.tsindex 1ef98a95dfc..8ba9a5aeb57 100644--- a/pages/api/credentials/index.ts+++ b/pages/api/credentials/index.ts@@ -3,8 +3,8 @@ import type { NextApiRequest, NextApiResponse } from "next";import prisma from "@calcom/prisma";import { withMiddleware } from "@lib/helpers/withMiddleware";-import { CredentialsResponse } from "@lib/types";-import { schemaCredentialPublic } from "@lib/validations/credential";+import { CredentialResponse, CredentialsResponse } from "@lib/types";+import { schemaCredentialBodyParams, schemaCredentialPublic } from "@lib/validations/credential";/*** @swagger@@ -20,18 +20,49 @@ import { schemaCredentialPublic } from "@lib/validations/credential";* description: Authorization information is missing or invalid.* 404:* description: No credentials were found+ * post:+ * summary: Creates a new credential+ * tags:+ * - credentials+ * responses:+ * 201:+ * description: OK, credential created+ * model: Credential+ * 400:+ * description: Bad request. Credential body is invalid.+ * 401:+ * description: Authorization information is missing or invalid.*/-async function allCredentials(_: NextApiRequest, res: NextApiResponse<CredentialsResponse>) {- const credentials = await prisma.credential.findMany();- const data = credentials.map((credential) => schemaCredentialPublic.parse(credential));+async function createOrlistAllCredentials(+ req: NextApiRequest,+ res: NextApiResponse<CredentialsResponse | CredentialResponse>+) {+ const { method } = req;+ if (method === "GET") {+ const data = await prisma.credential.findMany();+ const credentials = data.map((credential) => schemaCredentialPublic.parse(credential));+ if (credentials) res.status(200).json({ credentials });+ else+ (error: Error) =>+ res.status(404).json({+ message: "No Credentials were found",+ error,+ });+ } else if (method === "POST") {+ const safe = schemaCredentialBodyParams.safeParse(req.body);+ if (!safe.success) throw new Error("Invalid request body");++ const data = await prisma.credential.create({ data: safe.data });+ const credential = schemaCredentialPublic.parse(data);- if (data) res.status(200).json({ data });- else- (error: Error) =>- res.status(404).json({- message: "No Credentials were found",- error,- });+ if (credential) res.status(201).json({ credential, message: "Credential created successfully" });+ else+ (error: Error) =>+ res.status(400).json({+ message: "Could not create new credential",+ error,+ });+ } else res.status(405).json({ message: `Method ${method} not allowed` });}-export default withMiddleware("HTTP_GET")(allCredentials);+export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllCredentials);diff --git a/pages/api/credentials/new.ts b/pages/api/credentials/new.tsdeleted file mode 100644index 39302c7a1dc..00000000000--- a/pages/api/credentials/new.ts+++ /dev/null@@ -1,52 +0,0 @@-import type { NextApiRequest, NextApiResponse } from "next";--import prisma from "@calcom/prisma";--import { withMiddleware } from "@lib/helpers/withMiddleware";-import type { CredentialResponse } from "@lib/types";-import {- schemaCredentialBodyParams,- schemaCredentialPublic,- withValidCredential,-} from "@lib/validations/credential";--/**- * @swagger- * /api/credentials/new:- * post:- * summary: Creates a new credential- * requestBody:- * description: Optional description in *Markdown*- * required: true- * content:- * application/json:- * schema:- * $ref: '#/components/schemas/Credential'- * tags:- * - credentials- * responses:- * 201:- * description: OK, credential created- * model: Credential- * 400:- * description: Bad request. Credential body is invalid.- * 401:- * description: Authorization information is missing or invalid.- */-async function createCredential(req: NextApiRequest, res: NextApiResponse<CredentialResponse>) {- const safe = schemaCredentialBodyParams.safeParse(req.body);- if (!safe.success) throw new Error("Invalid request body", safe.error);-- const credential = await prisma.credential.create({ data: safe.data });- const data = schemaCredentialPublic.parse(credential);-- if (data) res.status(201).json({ data, message: "Credential created successfully" });- else- (error: Error) =>- res.status(400).json({- message: "Could not create new credential",- error,- });-}--export default withMiddleware("HTTP_POST")(withValidCredential(createCredential));diff --git a/pages/api/daily-event-references/[id].ts b/pages/api/daily-event-references/[id].tsindex d150cf69ce2..482aab6ec10 100644--- a/pages/api/daily-event-references/[id].ts+++ b/pages/api/daily-event-references/[id].ts@@ -15,7 +15,7 @@ import {/*** @swagger- * /api/daily-event-references/{id}:+ * /v1/daily-event-references/{id}:* get:* summary: Get a daily event reference by ID* parameters:@@ -96,7 +96,7 @@ export async function dailyEventReferenceById(await prisma.dailyEventReference.findUnique({ where: { id: safeQuery.data.id } }).then((data) => schemaDailyEventReferencePublic.parse(data))- .then((data) => res.status(200).json({ data }))+ .then((daily_event_reference) => res.status(200).json({ daily_event_reference })).catch((error: Error) =>res.status(404)@@ -111,8 +111,8 @@ export async function dailyEventReferenceById(where: { id: safeQuery.data.id },data: safeBody.data,})- .then((dailyEventReference) => schemaDailyEventReferencePublic.parse(dailyEventReference))- .then((data) => res.status(200).json({ data }))+ .then((data) => schemaDailyEventReferencePublic.parse(data))+ .then((daily_event_reference) => res.status(200).json({ daily_event_reference })).catch((error: Error) =>res.status(404)diff --git a/pages/api/daily-event-references/index.ts b/pages/api/daily-event-references/index.tsindex d4495ef0f1d..1a1762157d9 100644--- a/pages/api/daily-event-references/index.ts+++ b/pages/api/daily-event-references/index.ts@@ -3,40 +3,72 @@ import type { NextApiRequest, NextApiResponse } from "next";import prisma from "@calcom/prisma";import { withMiddleware } from "@lib/helpers/withMiddleware";-import { DailyEventReferencesResponse } from "@lib/types";-import { schemaDailyEventReferencePublic } from "@lib/validations/daily-event-reference";+import { DailyEventReferenceResponse, DailyEventReferencesResponse } from "@lib/types";+import {+ schemaDailyEventReferenceBodyParams,+ schemaDailyEventReferencePublic,+} from "@lib/validations/daily-event-reference";/*** @swagger- * /api/daily-event-references:+ * /v1/daily-event-references:* get:- * summary: Get all dailyEventReferences+ * summary: Get all daily event reference* tags:- * - daily-event-references+ * - daily-event-reference* responses:* 200:* description: OK* 401:* description: Authorization information is missing or invalid.* 404:- * description: No dailyEventReferences were found+ * description: No daily event references were found+ * post:+ * summary: Creates a new daily event reference+ * tags:+ * - daily-event-reference+ * responses:+ * 201:+ * description: OK, daily event reference created+ * model: DailyEventReference+ * 400:+ * description: Bad request. DailyEventReference body is invalid.+ * 401:+ * description: Authorization information is missing or invalid.*/-async function allDailyEventReferences(- _: NextApiRequest,- res: NextApiResponse<DailyEventReferencesResponse>+async function createOrlistAllDailyEventReferences(+ req: NextApiRequest,+ res: NextApiResponse<DailyEventReferencesResponse | DailyEventReferenceResponse>) {- const dailyEventReferences = await prisma.dailyEventReference.findMany();- const data = dailyEventReferences.map((dailyEventReference) =>- schemaDailyEventReferencePublic.parse(dailyEventReference)- );+ const { method } = req;+ if (method === "GET") {+ const data = await prisma.dailyEventReference.findMany();+ const daily_event_references = data.map((dailyEventReference) =>+ schemaDailyEventReferencePublic.parse(dailyEventReference)+ );+ if (daily_event_references) res.status(200).json({ daily_event_references });+ else+ (error: Error) =>+ res.status(404).json({+ message: "No DailyEventReferences were found",+ error,+ });+ } else if (method === "POST") {+ const safe = schemaDailyEventReferenceBodyParams.safeParse(req.body);+ if (!safe.success) throw new Error("Invalid request body");++ const data = await prisma.dailyEventReference.create({ data: safe.data });+ const daily_event_reference = schemaDailyEventReferencePublic.parse(data);- if (data) res.status(200).json({ data });- else- (error: Error) =>- res.status(404).json({- message: "No DailyEventReferences were found",- error,- });+ if (daily_event_reference)+ res.status(201).json({ daily_event_reference, message: "DailyEventReference created successfully" });+ else+ (error: Error) =>+ res.status(400).json({+ message: "Could not create new daily event reference",+ error,+ });+ } else res.status(405).json({ message: `Method ${method} not allowed` });}-export default withMiddleware("HTTP_GET")(allDailyEventReferences);+export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllDailyEventReferences);diff --git a/pages/api/daily-event-references/new.ts b/pages/api/daily-event-references/new.tsdeleted file mode 100644index 1e61a7fa59e..00000000000--- a/pages/api/daily-event-references/new.ts+++ /dev/null@@ -1,55 +0,0 @@-import type { NextApiRequest, NextApiResponse } from "next";--import prisma from "@calcom/prisma";--import { withMiddleware } from "@lib/helpers/withMiddleware";-import type { DailyEventReferenceResponse } from "@lib/types";-import {- schemaDailyEventReferenceBodyParams,- schemaDailyEventReferencePublic,- withValidDailyEventReference,-} from "@lib/validations/daily-event-reference";--/**- * @swagger- * /api/daily-event-references/new:- * post:- * summary: Creates a new dailyEventReference- * requestBody:- * description: Optional description in *Markdown*- * required: true- * content:- * application/json:- * schema:- * $ref: '#/components/schemas/DailyEventReference'- * tags:- * - daily-event-references- * responses:- * 201:- * description: OK, dailyEventReference created- * model: DailyEventReference- * 400:- * description: Bad request. DailyEventReference body is invalid.- * 401:- * description: Authorization information is missing or invalid.- */-async function createDailyEventReference(- req: NextApiRequest,- res: NextApiResponse<DailyEventReferenceResponse>-) {- const safe = schemaDailyEventReferenceBodyParams.safeParse(req.body);- if (!safe.success) throw new Error("Invalid request body", safe.error);-- const dailyEventReference = await prisma.dailyEventReference.create({ data: safe.data });- const data = schemaDailyEventReferencePublic.parse(dailyEventReference);-- if (data) res.status(201).json({ data, message: "DailyEventReference created successfully" });- else- (error: Error) =>- res.status(400).json({- message: "Could not create new dailyEventReference",- error,- });-}--export default withMiddleware("HTTP_POST")(withValidDailyEventReference(createDailyEventReference));diff --git a/pages/api/destination-calendars/[id].ts b/pages/api/destination-calendars/[id].tsindex 16c5fba7bea..a72bcecba1d 100644--- a/pages/api/destination-calendars/[id].ts+++ b/pages/api/destination-calendars/[id].ts@@ -15,7 +15,7 @@ import {/*** @swagger- * /api/destination-calendars/{id}:+ * /v1/destination-calendars/{id}:* get:* summary: Get a destination calendar by ID* parameters:@@ -96,7 +96,7 @@ export async function destionationCalendarById(await prisma.destinationCalendar.findUnique({ where: { id: safeQuery.data.id } }).then((data) => schemaDestinationCalendarPublic.parse(data))- .then((data) => res.status(200).json({ data }))+ .then((destination_calendar) => res.status(200).json({ destination_calendar })).catch((error: Error) =>res.status(404)@@ -111,8 +111,8 @@ export async function destionationCalendarById(where: { id: safeQuery.data.id },data: safeBody.data,})- .then((destinationCalendar) => schemaDestinationCalendarPublic.parse(destinationCalendar))- .then((data) => res.status(200).json({ data }))+ .then((data) => schemaDestinationCalendarPublic.parse(data))+ .then((destination_calendar) => res.status(200).json({ destination_calendar })).catch((error: Error) =>res.status(404)diff --git a/pages/api/destination-calendars/index.ts b/pages/api/destination-calendars/index.tsindex b031b8a27ef..3557272970f 100644--- a/pages/api/destination-calendars/index.ts+++ b/pages/api/destination-calendars/index.ts@@ -3,12 +3,15 @@ import type { NextApiRequest, NextApiResponse } from "next";import prisma from "@calcom/prisma";import { withMiddleware } from "@lib/helpers/withMiddleware";-import { DestinationCalendarsResponse } from "@lib/types";-import { schemaDestinationCalendarPublic } from "@lib/validations/destination-calendar";+import { DestinationCalendarResponse, DestinationCalendarsResponse } from "@lib/types";+import {+ schemaDestinationCalendarBodyParams,+ schemaDestinationCalendarPublic,+} from "@lib/validations/destination-calendar";/*** @swagger- * /api/destination-calendars:+ * /v1/destination-calendars:* get:* summary: Get all destination calendars* tags:@@ -19,24 +22,53 @@ import { schemaDestinationCalendarPublic } from "@lib/validations/destination-ca* 401:* description: Authorization information is missing or invalid.* 404:- * description: No destinationCalendars were found+ * description: No destination calendars were found+ * post:+ * summary: Creates a new destination calendar+ * tags:+ * - destination-calendars+ * responses:+ * 201:+ * description: OK, destination calendar created+ * model: DestinationCalendar+ * 400:+ * description: Bad request. DestinationCalendar body is invalid.+ * 401:+ * description: Authorization information is missing or invalid.*/-async function allDestinationCalendars(- _: NextApiRequest,- res: NextApiResponse<DestinationCalendarsResponse>+async function createOrlistAllDestinationCalendars(+ req: NextApiRequest,+ res: NextApiResponse<DestinationCalendarsResponse | DestinationCalendarResponse>) {- const destinationCalendars = await prisma.destinationCalendar.findMany();- const data = destinationCalendars.map((destinationCalendar) =>- schemaDestinationCalendarPublic.parse(destinationCalendar)- );+ const { method } = req;+ if (method === "GET") {+ const data = await prisma.destinationCalendar.findMany();+ const destination_calendars = data.map((destinationCalendar) =>+ schemaDestinationCalendarPublic.parse(destinationCalendar)+ );+ if (data) res.status(200).json({ destination_calendars });+ else+ (error: Error) =>+ res.status(404).json({+ message: "No DestinationCalendars were found",+ error,+ });+ } else if (method === "POST") {+ const safe = schemaDestinationCalendarBodyParams.safeParse(req.body);+ if (!safe.success) throw new Error("Invalid request body");++ const data = await prisma.destinationCalendar.create({ data: safe.data });+ const destination_calendar = schemaDestinationCalendarPublic.parse(data);- if (data) res.status(200).json({ data });- else- (error: Error) =>- res.status(404).json({- message: "No DestinationCalendars were found",- error,- });+ if (destination_calendar)+ res.status(201).json({ destination_calendar, message: "DestinationCalendar created successfully" });+ else+ (error: Error) =>+ res.status(400).json({+ message: "Could not create new destinationCalendar",+ error,+ });+ } else res.status(405).json({ message: `Method ${method} not allowed` });}-export default withMiddleware("HTTP_GET")(allDestinationCalendars);+export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllDestinationCalendars);diff --git a/pages/api/destination-calendars/new.ts b/pages/api/destination-calendars/new.tsdeleted file mode 100644index e98472b2163..00000000000--- a/pages/api/destination-calendars/new.ts+++ /dev/null@@ -1,55 +0,0 @@-import type { NextApiRequest, NextApiResponse } from "next";--import prisma from "@calcom/prisma";--import { withMiddleware } from "@lib/helpers/withMiddleware";-import type { DestinationCalendarResponse } from "@lib/types";-import {- schemaDestinationCalendarBodyParams,- schemaDestinationCalendarPublic,- withValidDestinationCalendar,-} from "@lib/validations/destination-calendar";--/**- * @swagger- * /api/destination-calendars/new:- * post:- * summary: Creates a new destination calendar- * requestBody:- * description: Optional description in *Markdown*- * required: true- * content:- * application/json:- * schema:- * $ref: '#/components/schemas/DestinationCalendar'- * tags:- * - destination-calendars- * responses:- * 201:- * description: OK, destinationCalendar created- * model: DestinationCalendar- * 400:- * description: Bad request. DestinationCalendar body is invalid.- * 401:- * description: Authorization information is missing or invalid.- */-async function createDestinationCalendar(- req: NextApiRequest,- res: NextApiResponse<DestinationCalendarResponse>-) {- const safe = schemaDestinationCalendarBodyParams.safeParse(req.body);- if (!safe.success) throw new Error("Invalid request body", safe.error);-- const destinationCalendar = await prisma.destinationCalendar.create({ data: safe.data });- const data = schemaDestinationCalendarPublic.parse(destinationCalendar);-- if (data) res.status(201).json({ data, message: "DestinationCalendar created successfully" });- else- (error: Error) =>- res.status(400).json({- message: "Could not create new destinationCalendar",- error,- });-}--export default withMiddleware("HTTP_POST")(withValidDestinationCalendar(createDestinationCalendar));diff --git a/pages/api/event-type-custom-inputs/[id].ts b/pages/api/event-type-custom-inputs/[id].tsindex c737b5fb84f..62b61d9c92d 100644--- a/pages/api/event-type-custom-inputs/[id].ts+++ b/pages/api/event-type-custom-inputs/[id].ts@@ -15,7 +15,7 @@ import {/*** @swagger- * /api/event-type-custom-inputs/{id}:+ * /v1/event-type-custom-inputs/{id}:* get:* summary: Get a eventTypeCustomInput by ID* parameters:@@ -93,7 +93,7 @@ async function eventTypeById(req: NextApiRequest, res: NextApiResponse<EventTypeawait prisma.eventTypeCustomInput.findUnique({ where: { id: safeQuery.data.id } }).then((data) => schemaEventTypeCustomInputPublic.parse(data))- .then((data) => res.status(200).json({ data }))+ .then((event_type_custom_input) => res.status(200).json({ event_type_custom_input })).catch((error: Error) =>res.status(404).json({ message: `EventType with id: ${safeQuery.data.id} not found`, error }));@@ -106,8 +106,8 @@ async function eventTypeById(req: NextApiRequest, res: NextApiResponse<EventTypewhere: { id: safeQuery.data.id },data: safeBody.data,})- .then((eventTypeCustomInput) => schemaEventTypeCustomInputPublic.parse(eventTypeCustomInput))- .then((data) => res.status(200).json({ data }))+ .then((data) => schemaEventTypeCustomInputPublic.parse(data))+ .then((event_type_custom_input) => res.status(200).json({ event_type_custom_input })).catch((error: Error) =>res.status(404).json({ message: `EventType with id: ${safeQuery.data.id} not found`, error }));diff --git a/pages/api/event-type-custom-inputs/index.ts b/pages/api/event-type-custom-inputs/index.tsindex d1c8e3ad90c..f988adc281b 100644--- a/pages/api/event-type-custom-inputs/index.ts+++ b/pages/api/event-type-custom-inputs/index.ts@@ -3,12 +3,15 @@ import type { NextApiRequest, NextApiResponse } from "next";import prisma from "@calcom/prisma";import { withMiddleware } from "@lib/helpers/withMiddleware";-import { EventTypeCustomInputsResponse } from "@lib/types";-import { schemaEventTypeCustomInputPublic } from "@lib/validations/event-type-custom-input";+import { EventTypeCustomInputResponse, EventTypeCustomInputsResponse } from "@lib/types";+import {+ schemaEventTypeCustomInputBodyParams,+ schemaEventTypeCustomInputPublic,+} from "@lib/validations/event-type-custom-input";/*** @swagger- * /api/event-type-custom-inputs:+ * /v1/event-type-custom-inputs:* get:* summary: Get all eventTypeCustomInputs* tags:@@ -20,23 +23,52 @@ import { schemaEventTypeCustomInputPublic } from "@lib/validations/event-type-cu* description: Authorization information is missing or invalid.* 404:* description: No eventTypeCustomInputs were found+ * post:+ * summary: Creates a new eventTypeCustomInput+ * tags:+ * - event-type-custom-inputs+ * responses:+ * 201:+ * description: OK, eventTypeCustomInput created+ * model: EventTypeCustomInput+ * 400:+ * description: Bad request. EventTypeCustomInput body is invalid.+ * 401:+ * description: Authorization information is missing or invalid.*/-async function allEventTypeCustomInputs(- _: NextApiRequest,- res: NextApiResponse<EventTypeCustomInputsResponse>+async function createOrlistAllEventTypeCustomInputs(+ req: NextApiRequest,+ res: NextApiResponse<EventTypeCustomInputsResponse | EventTypeCustomInputResponse>) {- const eventTypeCustomInputs = await prisma.eventTypeCustomInput.findMany();- const data = eventTypeCustomInputs.map((eventTypeCustomInput) =>- schemaEventTypeCustomInputPublic.parse(eventTypeCustomInput)- );+ const { method } = req;+ if (method === "GET") {+ const data = await prisma.eventTypeCustomInput.findMany();+ const event_type_custom_inputs = data.map((eventTypeCustomInput) =>+ schemaEventTypeCustomInputPublic.parse(eventTypeCustomInput)+ );+ if (event_type_custom_inputs) res.status(200).json({ event_type_custom_inputs });+ else+ (error: Error) =>+ res.status(404).json({+ message: "No EventTypeCustomInputs were found",+ error,+ });+ } else if (method === "POST") {+ const safe = schemaEventTypeCustomInputBodyParams.safeParse(req.body);+ if (!safe.success) throw new Error("Invalid request body");++ const data = await prisma.eventTypeCustomInput.create({ data: safe.data });+ const event_type_custom_input = schemaEventTypeCustomInputPublic.parse(data);- if (data) res.status(200).json({ data });- else- (error: Error) =>- res.status(404).json({- message: "No EventTypeCustomInputs were found",- error,- });+ if (event_type_custom_input)+ res.status(201).json({ event_type_custom_input, message: "EventTypeCustomInput created successfully" });+ else+ (error: Error) =>+ res.status(400).json({+ message: "Could not create new eventTypeCustomInput",+ error,+ });+ } else res.status(405).json({ message: `Method ${method} not allowed` });}-export default withMiddleware("HTTP_GET")(allEventTypeCustomInputs);+export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllEventTypeCustomInputs);diff --git a/pages/api/event-type-custom-inputs/new.ts b/pages/api/event-type-custom-inputs/new.tsdeleted file mode 100644index 3d64c296dd5..00000000000--- a/pages/api/event-type-custom-inputs/new.ts+++ /dev/null@@ -1,55 +0,0 @@-import type { NextApiRequest, NextApiResponse } from "next";--import prisma from "@calcom/prisma";--import { withMiddleware } from "@lib/helpers/withMiddleware";-import type { EventTypeCustomInputResponse } from "@lib/types";-import {- schemaEventTypeCustomInputBodyParams,- schemaEventTypeCustomInputPublic,- withValidEventTypeCustomInput,-} from "@lib/validations/event-type-custom-input";--/**- * @swagger- * /api/event-type-custom-inputs/new:- * post:- * summary: Creates a new eventTypeCustomInput- * requestBody:- * description: Optional description in *Markdown*- * required: true- * content:- * application/json:- * schema:- * $ref: '#/components/schemas/EventTypeCustomInput'- * tags:- * - event-type-custom-inputs- * responses:- * 201:- * description: OK, eventTypeCustomInput created- * model: EventTypeCustomInput- * 400:- * description: Bad request. EventTypeCustomInput body is invalid.- * 401:- * description: Authorization information is missing or invalid.- */-async function createEventTypeCustomInput(- req: NextApiRequest,- res: NextApiResponse<EventTypeCustomInputResponse>-) {- const safe = schemaEventTypeCustomInputBodyParams.safeParse(req.body);- if (!safe.success) throw new Error("Invalid request body", safe.error);-- const eventTypeCustomInput = await prisma.eventTypeCustomInput.create({ data: safe.data });- const data = schemaEventTypeCustomInputPublic.parse(eventTypeCustomInput);-- if (data) res.status(201).json({ data, message: "EventTypeCustomInput created successfully" });- else- (error: Error) =>- res.status(400).json({- message: "Could not create new eventTypeCustomInput",- error,- });-}--export default withMiddleware("HTTP_POST")(withValidEventTypeCustomInput(createEventTypeCustomInput));diff --git a/pages/api/event-types/[id].ts b/pages/api/event-types/[id].tsindex dd441f5cd32..e3ffe87f9be 100644--- a/pages/api/event-types/[id].ts+++ b/pages/api/event-types/[id].ts@@ -12,7 +12,7 @@ import {/*** @swagger- * /api/event-types/{id}:+ * /v1/event-types/{id}:* get:* summary: Get a eventType by ID* parameters:@@ -90,7 +90,7 @@ export async function eventTypeById(req: NextApiRequest, res: NextApiResponse<Evawait prisma.eventType.findUnique({ where: { id: safeQuery.data.id } }).then((data) => schemaEventTypePublic.parse(data))- .then((data) => res.status(200).json({ data }))+ .then((event_type) => res.status(200).json({ event_type })).catch((error: Error) =>res.status(404).json({ message: `EventType with id: ${safeQuery.data.id} not found`, error }));@@ -103,8 +103,8 @@ export async function eventTypeById(req: NextApiRequest, res: NextApiResponse<Evwhere: { id: safeQuery.data.id },data: safeBody.data,})- .then((eventType) => schemaEventTypePublic.parse(eventType))- .then((data) => res.status(200).json({ data }))+ .then((data) => schemaEventTypePublic.parse(data))+ .then((event_type) => res.status(200).json({ event_type })).catch((error: Error) =>res.status(404).json({ message: `EventType with id: ${safeQuery.data.id} not found`, error }));diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.tsindex a6264909197..724f0e97698 100644--- a/pages/api/event-types/index.ts+++ b/pages/api/event-types/index.ts@@ -3,14 +3,14 @@ import type { NextApiRequest, NextApiResponse } from "next";import prisma from "@calcom/prisma";import { withMiddleware } from "@lib/helpers/withMiddleware";-import { EventTypesResponse } from "@lib/types";-import { schemaEventTypePublic } from "@lib/validations/event-type";+import { EventTypeResponse, EventTypesResponse } from "@lib/types";+import { schemaEventTypeBodyParams, schemaEventTypePublic } from "@lib/validations/event-type";/*** @swagger- * /api/eventTypes:+ * /v1/event-types:* get:- * summary: Returns all eventTypes+ * summary: Get all event types* tags:* - event-types* responses:@@ -19,19 +19,50 @@ import { schemaEventTypePublic } from "@lib/validations/event-type";* 401:* description: Authorization information is missing or invalid.* 404:- * description: No eventTypes were found+ * description: No event types were found+ * post:+ * summary: Creates a new event type+ * tags:+ * - event-types+ * responses:+ * 201:+ * description: OK, event type created+ * model: EventType+ * 400:+ * description: Bad request. EventType body is invalid.+ * 401:+ * description: Authorization information is missing or invalid.*/-async function allEventTypes(_: NextApiRequest, res: NextApiResponse<EventTypesResponse>) {- const eventTypes = await prisma.eventType.findMany();- const data = eventTypes.map((eventType) => schemaEventTypePublic.parse(eventType));+async function createOrlistAllEventTypes(+ req: NextApiRequest,+ res: NextApiResponse<EventTypesResponse | EventTypeResponse>+) {+ const { method } = req;+ if (method === "GET") {+ const data = await prisma.eventType.findMany();+ const event_types = data.map((eventType) => schemaEventTypePublic.parse(eventType));+ if (event_types) res.status(200).json({ event_types });+ else+ (error: Error) =>+ res.status(404).json({+ message: "No EventTypes were found",+ error,+ });+ } else if (method === "POST") {+ const safe = schemaEventTypeBodyParams.safeParse(req.body);+ if (!safe.success) throw new Error("Invalid request body");++ const data = await prisma.eventType.create({ data: safe.data });+ const event_type = schemaEventTypePublic.parse(data);- if (data) res.status(200).json({ data });- else- (error: Error) =>- res.status(404).json({- message: "No EventTypes were found",- error,- });+ if (data) res.status(201).json({ event_type, message: "EventType created successfully" });+ else+ (error: Error) =>+ res.status(400).json({+ message: "Could not create new event type",+ error,+ });+ } else res.status(405).json({ message: `Method ${method} not allowed` });}-export default withMiddleware("HTTP_GET")(allEventTypes);+export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllEventTypes);diff --git a/pages/api/event-types/new.ts b/pages/api/event-types/new.tsdeleted file mode 100644index 491057c4539..00000000000--- a/pages/api/event-types/new.ts+++ /dev/null@@ -1,45 +0,0 @@-import type { NextApiRequest, NextApiResponse } from "next";--import prisma from "@calcom/prisma";--import { withMiddleware } from "@lib/helpers/withMiddleware";-import type { EventTypeResponse } from "@lib/types";-import {- schemaEventTypeBodyParams,- schemaEventTypePublic,- withValidEventType,-} from "@lib/validations/event-type";--/**- * @swagger- * /api/event-types/new:- * post:- * summary: Creates a new eventType- * tags:- * - event-types- * responses:- * 201:- * description: OK, eventType created- * model: EventType- * 400:- * description: Bad request. EventType body is invalid.- * 401:- * description: Authorization information is missing or invalid.- */-async function createEventType(req: NextApiRequest, res: NextApiResponse<EventTypeResponse>) {- const safe = schemaEventTypeBodyParams.safeParse(req.body);- if (!safe.success) throw new Error("Invalid request body", safe.error);-- const eventType = await prisma.eventType.create({ data: safe.data });- const data = schemaEventTypePublic.parse(eventType);-- if (data) res.status(201).json({ data, message: "EventType created successfully" });- else- (error: Error) =>- res.status(400).json({- message: "Could not create new eventType",- error,- });-}--export default withMiddleware("HTTP_POST")(withValidEventType(createEventType));diff --git a/pages/api/memberships/[id].ts b/pages/api/memberships/[id].tsindex 61f78cc6e8f..a963c023f57 100644--- a/pages/api/memberships/[id].ts+++ b/pages/api/memberships/[id].ts@@ -9,7 +9,7 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations//*** @swagger- * /api/memberships/{userId}_{teamId}:+ * /v1/memberships/{userId}_{teamId}:* get:* summary: Get a membership by userID and teamID* parameters:@@ -106,8 +106,8 @@ export async function membershipById(req: NextApiRequest, res: NextApiResponse<Mcase "GET":await prisma.membership.findUnique({ where: { userId_teamId: { userId: parseInt(userId), teamId: parseInt(teamId) } } })- .then((membership) => schemaMembershipPublic.parse(membership))- .then((data) => res.status(200).json({ data }))+ .then((data) => schemaMembershipPublic.parse(data))+ .then((membership) => res.status(200).json({ membership })).catch((error: Error) =>res.status(404).json({ message: `Membership with id: ${safeQuery.data.id} not found`, error }));@@ -120,8 +120,8 @@ export async function membershipById(req: NextApiRequest, res: NextApiResponse<Mwhere: { userId_teamId: { userId: parseInt(userId), teamId: parseInt(teamId) } },data: safeBody.data,})- .then((membership) => schemaMembershipPublic.parse(membership))- .then((data) => res.status(200).json({ data }))+ .then((data) => schemaMembershipPublic.parse(data))+ .then((membership) => res.status(200).json({ membership })).catch((error: Error) =>res.status(404).json({ message: `Membership with id: ${safeQuery.data.id} not found`, error }));diff --git a/pages/api/memberships/index.ts b/pages/api/memberships/index.tsindex d53670ce921..54b6e70c160 100644--- a/pages/api/memberships/index.ts+++ b/pages/api/memberships/index.ts@@ -3,14 +3,14 @@ import type { NextApiRequest, NextApiResponse } from "next";import prisma from "@calcom/prisma";import { withMiddleware } from "@lib/helpers/withMiddleware";-import { MembershipsResponse } from "@lib/types";-import { schemaMembershipPublic } from "@lib/validations/membership";+import { MembershipResponse, MembershipsResponse } from "@lib/types";+import { schemaMembershipBodyParams, schemaMembershipPublic } from "@lib/validations/membership";/*** @swagger- * /api/memberships:+ * /v1/memberships:* get:- * summary: Returns all memberships+ * summary: Get all memberships* tags:* - memberships* responses:@@ -20,18 +20,49 @@ import { schemaMembershipPublic } from "@lib/validations/membership";* description: Authorization information is missing or invalid.* 404:* description: No memberships were found+ * post:+ * summary: Creates a new membership+ * tags:+ * - memberships+ * responses:+ * 201:+ * description: OK, membership created+ * model: Membership+ * 400:+ * description: Bad request. Membership body is invalid.+ * 401:+ * description: Authorization information is missing or invalid.*/-async function allMemberships(_: NextApiRequest, res: NextApiResponse<MembershipsResponse>) {- const memberships = await prisma.membership.findMany();- const data = memberships.map((membership) => schemaMembershipPublic.parse(membership));+async function createOrlistAllMemberships(+ req: NextApiRequest,+ res: NextApiResponse<MembershipsResponse | MembershipResponse>+) {+ const { method } = req;+ if (method === "GET") {+ const data = await prisma.membership.findMany();+ const memberships = data.map((membership) => schemaMembershipPublic.parse(membership));+ if (memberships) res.status(200).json({ memberships });+ else+ (error: Error) =>+ res.status(404).json({+ message: "No Memberships were found",+ error,+ });+ } else if (method === "POST") {+ const safe = schemaMembershipBodyParams.safeParse(req.body);+ if (!safe.success) throw new Error("Invalid request body");++ const data = await prisma.membership.create({ data: safe.data });+ const membership = schemaMembershipPublic.parse(data);- if (data) res.status(200).json({ data });- else- (error: Error) =>- res.status(404).json({- message: "No Memberships were found",- error,- });+ if (membership) res.status(201).json({ membership, message: "Membership created successfully" });+ else+ (error: Error) =>+ res.status(400).json({+ message: "Could not create new membership",+ error,+ });+ } else res.status(405).json({ message: `Method ${method} not allowed` });}-export default withMiddleware("HTTP_GET")(allMemberships);+export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllMemberships);diff --git a/pages/api/memberships/new.ts b/pages/api/memberships/new.tsdeleted file mode 100644index e3b9dbe02f4..00000000000--- a/pages/api/memberships/new.ts+++ /dev/null@@ -1,45 +0,0 @@-import type { NextApiRequest, NextApiResponse } from "next";--import prisma from "@calcom/prisma";--import { withMiddleware } from "@lib/helpers/withMiddleware";-import type { MembershipResponse } from "@lib/types";-import {- schemaMembershipBodyParams,- schemaMembershipPublic,- withValidMembership,-} from "@lib/validations/membership";--/**- * @swagger- * /api/memberships/new:- * post:- * summary: Creates a new membership- * tags:- * - memberships- * responses:- * 201:- * description: OK, membership created- * model: Membership- * 400:- * description: Bad request. Membership body is invalid.- * 401:- * description: Authorization information is missing or invalid.- */-async function createMembership(req: NextApiRequest, res: NextApiResponse<MembershipResponse>) {- const safe = schemaMembershipBodyParams.safeParse(req.body);- if (!safe.success) throw new Error("Invalid request body", safe.error);-- const membership = await prisma.membership.create({ data: safe.data });- const data = schemaMembershipPublic.parse(membership);-- if (data) res.status(201).json({ data, message: "Membership created successfully" });- else- (error: Error) =>- res.status(400).json({- message: "Could not create new membership",- error,- });-}--export default withMiddleware("HTTP_POST")(withValidMembership(createMembership));diff --git a/pages/api/payments/[id].ts b/pages/api/payments/[id].tsindex bdd8766c699..cdedf473ece 100644--- a/pages/api/payments/[id].ts+++ b/pages/api/payments/[id].ts@@ -13,7 +13,7 @@ import {/*** @swagger- * /api/payments/{id}:+ * /v1/payments/{id}:* get:* summary: Get one of your own payments by ID* parameters:@@ -45,10 +45,10 @@ export async function paymentById(req: NextApiRequest, res: NextApiResponse<Paym});await prisma.payment.findUnique({ where: { id: safeQuery.data.id } })- .then((payment) => schemaPaymentPublic.parse(payment))- .then((data) => {- if (userWithBookings?.bookings.map((b) => b.id).includes(data.bookingId)) {- res.status(200).json({ data });+ .then((data) => schemaPaymentPublic.parse(data))+ .then((payment) => {+ if (userWithBookings?.bookings.map((b) => b.id).includes(payment.bookingId)) {+ res.status(200).json({ payment });} else {res.status(401).json({ message: "Unauthorized" });}diff --git a/pages/api/payments/index.ts b/pages/api/payments/index.tsindex 73b32a7d1cb..955cff0725e 100644--- a/pages/api/payments/index.ts+++ b/pages/api/payments/index.ts@@ -9,7 +9,7 @@ import { schemaPaymentPublic } from "@lib/validations/payment";/*** @swagger- * /api/payments:+ * /v1/payments:* get:* summary: Get all payments* tags:@@ -32,10 +32,10 @@ async function allPayments(_: NextApiRequest, res: NextApiResponse<PaymentsRespoif (!userWithBookings) throw new Error("No user found");const bookings = userWithBookings.bookings;const bookingIds = bookings.map((booking) => booking.id);- const payments = await prisma.payment.findMany({ where: { bookingId: { in: bookingIds } } });- const data = payments.map((payment) => schemaPaymentPublic.parse(payment));+ const data = await prisma.payment.findMany({ where: { bookingId: { in: bookingIds } } });+ const payments = data.map((payment) => schemaPaymentPublic.parse(payment));- if (data) res.status(200).json({ data });+ if (payments) res.status(200).json({ payments });else(error: Error) =>res.status(404).json({@@ -43,5 +43,5 @@ async function allPayments(_: NextApiRequest, res: NextApiResponse<PaymentsRespoerror,});}-+// NO POST FOR PAYMENTS FOR NOWexport default withMiddleware("HTTP_GET")(allPayments);diff --git a/pages/api/reminder-mails/[id].ts b/pages/api/reminder-mails/[id].tsindex 543b84de9bc..10c5dd41e65 100644--- a/pages/api/reminder-mails/[id].ts+++ b/pages/api/reminder-mails/[id].ts@@ -12,7 +12,7 @@ import {/*** @swagger- * /api/reminder-mails/{id}:+ * /v1/reminder-mails/{id}:* get:* summary: Get a reminderMail by ID* parameters:@@ -90,7 +90,7 @@ export async function reminderMailById(req: NextApiRequest, res: NextApiResponseawait prisma.reminderMail.findUnique({ where: { id: safeQuery.data.id } }).then((data) => schemaReminderMailPublic.parse(data))- .then((data) => res.status(200).json({ data }))+ .then((reminder_mail) => res.status(200).json({ reminder_mail })).catch((error: Error) =>res.status(404).json({ message: `ReminderMail with id: ${safeQuery.data.id} not found`, error }));@@ -104,7 +104,7 @@ export async function reminderMailById(req: NextApiRequest, res: NextApiResponsedata: safeBody.data,}).then((reminderMail) => schemaReminderMailPublic.parse(reminderMail))- .then((data) => res.status(200).json({ data }))+ .then((reminder_mail) => res.status(200).json({ reminder_mail })).catch((error: Error) =>res.status(404).json({ message: `ReminderMail with id: ${safeQuery.data.id} not found`, error }));diff --git a/pages/api/reminder-mails/index.ts b/pages/api/reminder-mails/index.tsindex be7025ba216..2c743c0474b 100644--- a/pages/api/reminder-mails/index.ts+++ b/pages/api/reminder-mails/index.ts@@ -43,9 +43,9 @@ async function createOrlistAllReminderMails() {const { method } = req;if (method === "GET") {- const reminderMails = await prisma.reminderMail.findMany();- const data = reminderMails.map((reminderMail) => schemaReminderMailPublic.parse(reminderMail));- if (data) res.status(200).json({ data });+ const data = await prisma.reminderMail.findMany();+ const reminder_mails = data.map((reminderMail) => schemaReminderMailPublic.parse(reminderMail));+ if (reminder_mails) res.status(200).json({ reminder_mails });else(error: Error) =>res.status(404).json({@@ -56,10 +56,10 @@ async function createOrlistAllReminderMails(const safe = schemaReminderMailBodyParams.safeParse(req.body);if (!safe.success) throw new Error("Invalid request body");- const reminderMail = await prisma.reminderMail.create({ data: safe.data });- const data = schemaReminderMailPublic.parse(reminderMail);+ const data = await prisma.reminderMail.create({ data: safe.data });+ const reminder_mail = schemaReminderMailPublic.parse(data);- if (data) res.status(201).json({ data, message: "reminder mail created successfully" });+ if (reminder_mail) res.status(201).json({ reminder_mail, message: "reminder mail created successfully" });else(error: Error) =>res.status(400).json({diff --git a/pages/api/schedules/[id].ts b/pages/api/schedules/[id].tsindex 162f7f95422..c75034e5d14 100644--- a/pages/api/schedules/[id].ts+++ b/pages/api/schedules/[id].ts@@ -89,8 +89,8 @@ export async function scheduleById(req: NextApiRequest, res: NextApiResponse<Schcase "GET":await prisma.schedule.findUnique({ where: { id: safeQuery.data.id } })- .then((schedule) => schemaSchedulePublic.parse(schedule))- .then((data) => res.status(200).json({ data }))+ .then((data) => schemaSchedulePublic.parse(data))+ .then((schedule) => res.status(200).json({ schedule })).catch((error: Error) =>res.status(404).json({ message: `Schedule with id: ${safeQuery.data.id} not found`, error }));@@ -103,8 +103,8 @@ export async function scheduleById(req: NextApiRequest, res: NextApiResponse<Schwhere: { id: safeQuery.data.id },data: safeBody.data,})- .then((schedule) => schemaSchedulePublic.parse(schedule))- .then((data) => res.status(200).json({ data }))+ .then((data) => schemaSchedulePublic.parse(data))+ .then((schedule) => res.status(200).json({ schedule })).catch((error: Error) =>res.status(404).json({ message: `Schedule with id: ${safeQuery.data.id} not found`, error }));diff --git a/pages/api/schedules/index.ts b/pages/api/schedules/index.tsindex e3b178d2169..f8eedf599f5 100644--- a/pages/api/schedules/index.ts+++ b/pages/api/schedules/index.ts@@ -39,9 +39,9 @@ async function createOrlistAllSchedules() {const { method } = req;if (method === "GET") {- const schedules = await prisma.schedule.findMany();- const data = schedules.map((schedule) => schemaSchedulePublic.parse(schedule));- if (data) res.status(200).json({ data });+ const data = await prisma.schedule.findMany();+ const schedules = data.map((schedule) => schemaSchedulePublic.parse(schedule));+ if (schedules) res.status(200).json({ schedules });else(error: Error) =>res.status(404).json({@@ -52,10 +52,10 @@ async function createOrlistAllSchedules(const safe = schemaScheduleBodyParams.safeParse(req.body);if (!safe.success) throw new Error("Invalid request body");- const schedule = await prisma.schedule.create({ data: safe.data });- const data = schemaSchedulePublic.parse(schedule);+ const data = await prisma.schedule.create({ data: safe.data });+ const schedule = schemaSchedulePublic.parse(data);- if (data) res.status(201).json({ data, message: "Schedule created successfully" });+ if (schedule) res.status(201).json({ schedule, message: "Schedule created successfully" });else(error: Error) =>res.status(400).json({diff --git a/templates/endpoints/[id]/delete.ts b/templates/endpoints/[id]/delete.tsindex a9816a3ab6d..2b59baee902 100644--- a/templates/endpoints/[id]/delete.ts+++ b/templates/endpoints/[id]/delete.ts@@ -11,7 +11,7 @@ import {/*** @swagger- * /api/resources/{id}/delete:+ * /v1/resources/{id}/delete:* delete:* summary: Remove an existing resource* parameters:diff --git a/templates/endpoints/[id]/edit.ts b/templates/endpoints/[id]/edit.tsindex 2be7bd06c1c..0e73604fb47 100644--- a/templates/endpoints/[id]/edit.ts+++ b/templates/endpoints/[id]/edit.ts@@ -4,15 +4,15 @@ import prisma from "@calcom/prisma";import { withMiddleware } from "@lib/helpers/withMiddleware";import type { ResourceResponse } from "@lib/types";+import { schemaResourceBodyParams, schemaResourcePublic, withValidResource } from "@lib/validations/resource";import {schemaQueryIdParseInt,withValidQueryIdTransformParseInt,} from "@lib/validations/shared/queryIdTransformParseInt";-import { schemaResourceBodyParams, schemaResourcePublic, withValidResource } from "@lib/validations/resource";/*** @swagger- * /api/resources/{id}/edit:+ * /v1/resources/{id}/edit:* patch:* summary: Edit an existing resource* parameters:@@ -53,4 +53,6 @@ export async function editResource(req: NextApiRequest, res: NextApiResponse<Res});}-export default withMiddleware("HTTP_PATCH")(withValidQueryIdTransformParseInt(withValidResource(editResource)));+export default withMiddleware("HTTP_PATCH")(+ withValidQueryIdTransformParseInt(withValidResource(editResource))+);diff --git a/templates/endpoints/[id]/index.ts b/templates/endpoints/[id]/index.tsindex 2ef4d18a674..31393a7a6ab 100644--- a/templates/endpoints/[id]/index.ts+++ b/templates/endpoints/[id]/index.ts@@ -4,15 +4,15 @@ import prisma from "@calcom/prisma";import { withMiddleware } from "@lib/helpers/withMiddleware";import type { ResourceResponse } from "@lib/types";+import { schemaResourcePublic } from "@lib/validations/resource";import {schemaQueryIdParseInt,withValidQueryIdTransformParseInt,} from "@lib/validations/shared/queryIdTransformParseInt";-import { schemaResourcePublic } from "@lib/validations/resource";/*** @swagger- * /api/resources/{id}:+ * /v1/resources/{id}:* get:* summary: Get a resource by ID* parameters:diff --git a/templates/endpoints/index.ts b/templates/endpoints/get_all.tssimilarity index 98%rename from templates/endpoints/index.tsrename to templates/endpoints/get_all.tsindex 4c4c98b4971..490381501ef 100644--- a/templates/endpoints/index.ts+++ b/templates/endpoints/get_all.ts@@ -8,7 +8,7 @@ import { schemaResourcePublic } from "@lib/validations/resource";/*** @swagger- * /api/resources:+ * /v1/resources:* get:* summary: Get all resources* tags:diff --git a/templates/endpoints/newIndex.ts b/templates/endpoints/get_all_and_post.tssimilarity index 94%rename from templates/endpoints/newIndex.tsrename to templates/endpoints/get_all_and_post.tsindex 5d608ee0cb6..25115ff859b 100644--- a/templates/endpoints/newIndex.ts+++ b/templates/endpoints/get_all_and_post.ts@@ -4,11 +4,11 @@ import prisma from "@calcom/prisma";import { withMiddleware } from "@lib/helpers/withMiddleware";import { PaymentResponse, PaymentsResponse } from "@lib/types";-import { schemaPaymentBodyParams, schemaPaymentPublic, withValidPayment } from "@lib/validations/payment";+import { schemaPaymentBodyParams, schemaPaymentPublic } from "@lib/validations/payment";/*** @swagger- * /api/payments:+ * /v1/payments:* get:* summary: Get all payments* tags:diff --git a/templates/endpoints/new.ts b/templates/endpoints/post.tssimilarity index 98%rename from templates/endpoints/new.tsrename to templates/endpoints/post.tsindex bb1b0b26d2c..af0644a7a81 100644--- a/templates/endpoints/new.ts+++ b/templates/endpoints/post.ts@@ -8,7 +8,7 @@ import { schemaResourceBodyParams, schemaResourcePublic, withValidResource } fro/*** @swagger- * /api/resources/new:+ * /v1/resources/new:* post:* summary: Creates a new resource* requestBody: