Skip to content

Scheduling infrastructure for absolutely everyone.

fix: improve comments, no anys

Agusti Fernandez Pardo9bb0f8207599
diff --git a/pages/api/attendees/[id].ts b/pages/api/attendees/[id].ts
index b0bf73796fc..4e044790a4a 100644
--- a/pages/api/attendees/[id].ts
+++ b/pages/api/attendees/[id].ts
@@ -41,7 +41,7 @@ export async function attendeeById(
* @swagger
* /attendees/{id}:
* get:
- * summary: Find an attendee by ID
+ * summary: Find an attendee
* parameters:
* - in: path
* name: id
diff --git a/pages/api/attendees/index.ts b/pages/api/attendees/index.ts
index 4f57b8e9b7b..18bbce51d72 100644
--- a/pages/api/attendees/index.ts
+++ b/pages/api/attendees/index.ts
@@ -95,7 +95,7 @@ async function createOrlistAllAttendees(
if (!userWithBookings) {
throw new Error("User not found");
}
- const userBookingIds = userWithBookings.bookings.map((booking: any) => booking.id).flat();
+ const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat();
// Here we make sure to only return attendee's of the user's own bookings.
if (!userBookingIds.includes(safePost.data.bookingId)) res.status(401).json({ message: "Unauthorized" });
else {
diff --git a/pages/api/availabilities/[id].ts b/pages/api/availabilities/[id].ts
index de131eb0ff1..139e36e22f5 100644
--- a/pages/api/availabilities/[id].ts
+++ b/pages/api/availabilities/[id].ts
@@ -28,7 +28,7 @@ export async function availabilityById(
* @swagger
* /availabilities/{id}:
* get:
- * summary: Find an availability by ID
+ * summary: Find an availability
* parameters:
* - in: path
* name: id
diff --git a/pages/api/booking-references/[id].ts b/pages/api/booking-references/[id].ts
index bbc2ea6fa2a..cb0358d9019 100644
--- a/pages/api/booking-references/[id].ts
+++ b/pages/api/booking-references/[id].ts
@@ -25,7 +25,7 @@ export async function bookingReferenceById(
include: { bookings: true },
});
if (!userWithBookings) throw new Error("User not found");
- const userBookingIds = userWithBookings.bookings.map((booking: any) => booking.id).flat();
+ const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat();
const bookingReference = await prisma.bookingReference.findUnique({ where: { id: safeQuery.data.id } });
if (!bookingReference) throw new Error("BookingReference not found");
if (userBookingIds.includes(bookingReference.bookingId)) {
@@ -34,7 +34,7 @@ export async function bookingReferenceById(
* @swagger
* /booking-references/{id}:
* get:
- * summary: Find a booking reference by ID
+ * summary: Find a booking reference
* parameters:
* - in: path
* name: id
diff --git a/pages/api/booking-references/index.ts b/pages/api/booking-references/index.ts
index a4ced04215c..87cbe25cdcf 100644
--- a/pages/api/booking-references/index.ts
+++ b/pages/api/booking-references/index.ts
@@ -10,7 +10,7 @@ import {
} from "@lib/validations/booking-reference";
async function createOrlistAllBookingReferences(
- { method, userId }: NextApiRequest,
+ { method, userId, body }: NextApiRequest,
res: NextApiResponse<BookingReferencesResponse | BookingReferenceResponse>
) {
const userWithBookings = await prisma.user.findUnique({
@@ -18,7 +18,7 @@ async function createOrlistAllBookingReferences(
include: { bookings: true },
});
if (!userWithBookings) throw new Error("User not found");
- const userBookingIds = userWithBookings.bookings.map((booking: any) => booking.id).flat();
+ const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat();
if (method === "GET") {
/**
* @swagger
@@ -62,13 +62,11 @@ async function createOrlistAllBookingReferences(
* 401:
* description: Authorization information is missing or invalid.
*/
- const safe = schemaBookingCreateBodyParams.safeParse(req.body);
+ const safe = schemaBookingCreateBodyParams.safeParse(body);
if (!safe.success) {
throw new Error("Invalid request body");
}
- // const booking_reference = schemaBookingReferencePublic.parse(data);
- const userId = req.userId;
const userWithBookings = await prisma.user.findUnique({
where: { id: userId },
include: { bookings: true },
@@ -76,7 +74,7 @@ async function createOrlistAllBookingReferences(
if (!userWithBookings) {
throw new Error("User not found");
}
- const userBookingIds = userWithBookings.bookings.map((booking: any) => booking.id).flat();
+ const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat();
if (!userBookingIds.includes(safe.data.bookingId)) res.status(401).json({ message: "Unauthorized" });
else {
const booking_reference = await prisma.bookingReference.create({
diff --git a/pages/api/bookings/[id].ts b/pages/api/bookings/[id].ts
index 0974bd55b16..21fdd9a937e 100644
--- a/pages/api/bookings/[id].ts
+++ b/pages/api/bookings/[id].ts
@@ -10,17 +10,18 @@ import {
withValidQueryIdTransformParseInt,
} from "@lib/validations/shared/queryIdTransformParseInt";
-export async function bookingById(req: NextApiRequest, res: NextApiResponse<BookingResponse>) {
- const { method, query, body } = req;
+export async function bookingById(
+ { method, query, body, userId }: NextApiRequest,
+ res: NextApiResponse<BookingResponse>
+) {
const safeQuery = schemaQueryIdParseInt.safeParse(query);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
- const userId = req.userId;
const userWithBookings = await prisma.user.findUnique({
where: { id: userId },
include: { bookings: true },
});
if (!userWithBookings) throw new Error("User not found");
- const userBookingIds = userWithBookings.bookings.map((booking: any) => booking.id).flat();
+ const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat();
if (!userBookingIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" });
else {
switch (method) {
@@ -28,7 +29,7 @@ export async function bookingById(req: NextApiRequest, res: NextApiResponse<Book
* @swagger
* /bookings/{id}:
* get:
- * summary: Find a booking by ID
+ * summary: Find a booking
* parameters:
* - in: path
* name: id
diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts
index 440bc876fbf..57a774a916a 100644
--- a/pages/api/bookings/index.ts
+++ b/pages/api/bookings/index.ts
@@ -7,29 +7,25 @@ import { BookingResponse, BookingsResponse } from "@lib/types";
import { schemaBookingCreateBodyParams, schemaBookingReadPublic } from "@lib/validations/booking";
async function createOrlistAllBookings(
- req: NextApiRequest,
+ { method, userId }: NextApiRequest,
res: NextApiResponse<BookingsResponse | BookingResponse>
) {
- const { method } = req;
- const userId = req.userId;
-
if (method === "GET") {
-
-/**
- * @swagger
- * /bookings:
- * get:
- * summary: Find all bookings
- * tags:
- * - bookings
- * responses:
- * 200:
- * description: OK
- * 401:
- * description: Authorization information is missing or invalid.
- * 404:
- * description: No bookings were found
- */
+ /**
+ * @swagger
+ * /bookings:
+ * get:
+ * summary: Find all bookings
+ * tags:
+ * - bookings
+ * responses:
+ * 200:
+ * description: OK
+ * 401:
+ * description: Authorization information is missing or invalid.
+ * 404:
+ * description: No bookings were found
+ */
const data = await prisma.booking.findMany({ where: { userId } });
const bookings = data.map((booking) => schemaBookingReadPublic.parse(booking));
if (bookings) res.status(200).json({ bookings });
@@ -40,22 +36,21 @@ async function createOrlistAllBookings(
error,
});
} else if (method === "POST") {
-
-/**
- * @swagger
- * /bookings:
- * post:
- * summary: Creates a new booking
- * tags:
- * - bookings
- * responses:
- * 201:
- * description: OK, booking created
- * 400:
- * description: Bad request. Booking body is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- */
+ /**
+ * @swagger
+ * /bookings:
+ * post:
+ * summary: Creates a new booking
+ * tags:
+ * - bookings
+ * responses:
+ * 201:
+ * description: OK, booking created
+ * 400:
+ * description: Bad request. Booking body is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
const safe = schemaBookingCreateBodyParams.safeParse(req.body);
if (!safe.success) throw new Error("Invalid request body");
diff --git a/pages/api/custom-inputs/[id].ts b/pages/api/custom-inputs/[id].ts
index 2860d9a525e..3339f31027f 100644
--- a/pages/api/custom-inputs/[id].ts
+++ b/pages/api/custom-inputs/[id].ts
@@ -17,7 +17,7 @@ import {
* @swagger
* /custom-inputs/{id}:
* get:
- * summary: Find a eventTypeCustomInput by ID
+ * summary: Find a eventTypeCustomInput
* parameters:
* - in: path
* name: id
@@ -71,12 +71,13 @@ import {
* 401:
* description: Authorization information is missing or invalid.
*/
-async function eventTypeById(req: NextApiRequest, res: NextApiResponse<EventTypeCustomInputResponse>) {
- const { method, query, body } = req;
+async function eventTypeById(
+ { method, query, body, userId }: NextApiRequest,
+ res: NextApiResponse<EventTypeCustomInputResponse>
+) {
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaEventTypeCustomInputBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
- const userId = req.userId;
const data = await prisma.eventType.findMany({ where: { userId } });
const userEventTypes = data.map((eventType) => eventType.id);
const userEventTypeCustomInputs = await prisma.eventTypeCustomInput.findMany({
diff --git a/pages/api/custom-inputs/index.ts b/pages/api/custom-inputs/index.ts
index ee1232d83cb..c7d5f9df901 100644
--- a/pages/api/custom-inputs/index.ts
+++ b/pages/api/custom-inputs/index.ts
@@ -9,42 +9,28 @@ import {
schemaEventTypeCustomInputPublic,
} from "@lib/validations/event-type-custom-input";
-/**
- * @swagger
- * /custom-inputs:
- * get:
- * summary: Find all eventTypeCustomInputs
- * tags:
- * - custom-inputs
- * responses:
- * 200:
- * description: OK
- * 401:
- * description: Authorization information is missing or invalid.
- * 404:
- * description: No eventTypeCustomInputs were found
- * post:
- * summary: Creates a new eventTypeCustomInput
- * tags:
- * - custom-inputs
- * responses:
- * 201:
- * description: OK, eventTypeCustomInput created
- * 400:
- * description: Bad request. EventTypeCustomInput body is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- */
async function createOrlistAllEventTypeCustomInputs(
- req: NextApiRequest,
+ { userId, method, body }: NextApiRequest,
res: NextApiResponse<EventTypeCustomInputsResponse | EventTypeCustomInputResponse>
) {
- const { method } = req;
- const userId = req.userId;
const data = await prisma.eventType.findMany({ where: { userId } });
- const userEventTypes = data.map((eventType) => eventType.id);
-
+ const userEventTypes: number[] = data.map((eventType) => eventType.id);
if (method === "GET") {
+ /**
+ * @swagger
+ * /custom-inputs:
+ * get:
+ * summary: Find all eventTypeCustomInputs
+ * tags:
+ * - custom-inputs
+ * responses:
+ * 200:
+ * description: OK
+ * 401:
+ * description: Authorization information is missing or invalid.
+ * 404:
+ * description: No eventTypeCustomInputs were found
+ */
const data = await prisma.eventTypeCustomInput.findMany({ where: { eventType: userEventTypes } });
const event_type_custom_inputs = data.map((eventTypeCustomInput) =>
schemaEventTypeCustomInputPublic.parse(eventTypeCustomInput)
@@ -57,7 +43,22 @@ async function createOrlistAllEventTypeCustomInputs(
error,
});
} else if (method === "POST") {
- const safe = schemaEventTypeCustomInputBodyParams.safeParse(req.body);
+ /**
+ * @swagger
+ * /custom-inputs:
+ * post:
+ * summary: Creates a new eventTypeCustomInput
+ * tags:
+ * - custom-inputs
+ * responses:
+ * 201:
+ * description: OK, eventTypeCustomInput created
+ * 400:
+ * description: Bad request. EventTypeCustomInput body is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
+ const safe = schemaEventTypeCustomInputBodyParams.safeParse(body);
if (!safe.success) throw new Error("Invalid request body");
// Since we're supporting a create or connect relation on eventType, we need to treat them differently
// When using connect on event type, check if userId is the owner of the event
diff --git a/pages/api/destination-calendars/[id].ts b/pages/api/destination-calendars/[id].ts
index 679dcd5d294..f5d187eb255 100644
--- a/pages/api/destination-calendars/[id].ts
+++ b/pages/api/destination-calendars/[id].ts
@@ -13,74 +13,13 @@ import {
withValidQueryIdTransformParseInt,
} from "@lib/validations/shared/queryIdTransformParseInt";
-/**
- * @swagger
- * /destination-calendars/{id}:
- * get:
- * summary: Find a destination calendar by ID
- * parameters:
- * - in: path
- * name: id
- * schema:
- * type: integer
- * required: true
- * description: Numeric ID of the destination calendar to get
- * tags:
- * - destination-calendars
- * responses:
- * 200:
- * description: OK
- * 401:
- * description: Authorization information is missing or invalid.
- * 404:
- * description: DestinationCalendar was not found
- * patch:
- * summary: Edit an existing destination calendar
- * parameters:
- * - in: path
- * name: id
- * schema:
- * type: integer
- * required: true
- * description: Numeric ID of the destination calendar to edit
- * tags:
- * - destination-calendars
- * responses:
- * 201:
- * description: OK, destinationCalendar edited successfuly
- * 400:
- * description: Bad request. DestinationCalendar body is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- * delete:
- * summary: Remove an existing destination calendar
- * parameters:
- * - in: path
- * name: id
- * schema:
- * type: integer
- * required: true
- * description: Numeric ID of the destination calendar to delete
-
- * tags:
- * - destination-calendars
- * responses:
- * 201:
- * description: OK, destinationCalendar removed successfuly
- * 400:
- * description: Bad request. DestinationCalendar id is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- */
export async function destionationCalendarById(
- req: NextApiRequest,
+ { method, query, body, userId }: NextApiRequest,
res: NextApiResponse<DestinationCalendarResponse>
) {
- const { method, query, body } = req;
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaDestinationCalendarEditBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
- const userId = req.userId;
const data = await prisma.destinationCalendar.findMany({ where: { userId } });
const userDestinationCalendars = data.map((destinationCalendar) => destinationCalendar.id);
// FIXME: Should we also check ownership of bokingId and eventTypeId to avoid users cross-pollinating other users calendars.
@@ -88,6 +27,64 @@ export async function destionationCalendarById(
if (userDestinationCalendars.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" });
else {
switch (method) {
+ /**
+ * @swagger
+ * /destination-calendars/{id}:
+ * get:
+ * summary: Find a destination calendar
+ * parameters:
+ * - in: path
+ * name: id
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric ID of the destination calendar to get
+ * tags:
+ * - destination-calendars
+ * responses:
+ * 200:
+ * description: OK
+ * 401:
+ * description: Authorization information is missing or invalid.
+ * 404:
+ * description: DestinationCalendar was not found
+ * patch:
+ * summary: Edit an existing destination calendar
+ * parameters:
+ * - in: path
+ * name: id
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric ID of the destination calendar to edit
+ * tags:
+ * - destination-calendars
+ * responses:
+ * 201:
+ * description: OK, destinationCalendar edited successfuly
+ * 400:
+ * description: Bad request. DestinationCalendar body is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ * delete:
+ * summary: Remove an existing destination calendar
+ * parameters:
+ * - in: path
+ * name: id
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric ID of the destination calendar to delete
+ * tags:
+ * - destination-calendars
+ * responses:
+ * 201:
+ * description: OK, destinationCalendar removed successfuly
+ * 400:
+ * description: Bad request. DestinationCalendar id is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
case "GET":
await prisma.destinationCalendar
.findUnique({ where: { id: safeQuery.data.id } })
@@ -100,7 +97,28 @@ export async function destionationCalendarById(
})
);
break;
-
+ /**
+ * @swagger
+ * /destination-calendars/{id}:
+ * patch:
+ * summary: Edit an existing destination calendar
+ * parameters:
+ * - in: path
+ * name: id
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric ID of the destination calendar to edit
+ * tags:
+ * - destination-calendars
+ * responses:
+ * 201:
+ * description: OK, destinationCalendar edited successfuly
+ * 400:
+ * description: Bad request. DestinationCalendar body is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
case "PATCH":
if (!safeBody.success) {
throw new Error("Invalid request body");
@@ -116,7 +134,28 @@ export async function destionationCalendarById(
})
);
break;
-
+ /**
+ * @swagger
+ * /destination-calendars/{id}:
+ * delete:
+ * summary: Remove an existing destination calendar
+ * parameters:
+ * - in: path
+ * name: id
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric ID of the destination calendar to delete
+ * tags:
+ * - destination-calendars
+ * responses:
+ * 201:
+ * description: OK, destinationCalendar removed successfuly
+ * 400:
+ * description: Bad request. DestinationCalendar id is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
case "DELETE":
await prisma.destinationCalendar
.delete({
diff --git a/pages/api/destination-calendars/index.ts b/pages/api/destination-calendars/index.ts
index 81a3d36c977..4006a67c728 100644
--- a/pages/api/destination-calendars/index.ts
+++ b/pages/api/destination-calendars/index.ts
@@ -9,40 +9,26 @@ import {
schemaDestinationCalendarReadPublic,
} from "@lib/validations/destination-calendar";
-/**
- * @swagger
- * /destination-calendars:
- * get:
- * summary: Find all destination calendars
- * tags:
- * - destination-calendars
- * responses:
- * 200:
- * description: OK
- * 401:
- * description: Authorization information is missing or invalid.
- * 404:
- * description: No destination calendars were found
- * post:
- * summary: Creates a new destination calendar
- * tags:
- * - destination-calendars
- * responses:
- * 201:
- * description: OK, destination calendar created
- * 400:
- * description: Bad request. DestinationCalendar body is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- */
async function createOrlistAllDestinationCalendars(
- req: NextApiRequest,
+ { method, body, userId }: NextApiRequest,
res: NextApiResponse<DestinationCalendarsResponse | DestinationCalendarResponse>
) {
- const { method } = req;
- const userId = req.userId;
-
if (method === "GET") {
+ /**
+ * @swagger
+ * /destination-calendars:
+ * get:
+ * summary: Find all destination calendars
+ * tags:
+ * - destination-calendars
+ * responses:
+ * 200:
+ * description: OK
+ * 401:
+ * description: Authorization information is missing or invalid.
+ * 404:
+ * description: No destination calendars were found
+ */
const data = await prisma.destinationCalendar.findMany({ where: { userId } });
const destination_calendars = data.map((destinationCalendar) =>
schemaDestinationCalendarReadPublic.parse(destinationCalendar)
@@ -55,7 +41,22 @@ async function createOrlistAllDestinationCalendars(
error,
});
} else if (method === "POST") {
- const safe = schemaDestinationCalendarCreateBodyParams.safeParse(req.body);
+ /**
+ * @swagger
+ * /destination-calendars:
+ * post:
+ * summary: Creates a new destination calendar
+ * tags:
+ * - destination-calendars
+ * responses:
+ * 201:
+ * description: OK, destination calendar created
+ * 400:
+ * description: Bad request. DestinationCalendar body is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
+ const safe = schemaDestinationCalendarCreateBodyParams.safeParse(body);
if (!safe.success) throw new Error("Invalid request body");
const data = await prisma.destinationCalendar.create({ data: { ...safe.data, userId } });
diff --git a/pages/api/event-references/[id].ts b/pages/api/event-references/[id].ts
index d0a31fcf111..a98d5f74e9e 100644
--- a/pages/api/event-references/[id].ts
+++ b/pages/api/event-references/[id].ts
@@ -14,16 +14,14 @@ import {
} from "@lib/validations/shared/queryIdTransformParseInt";
export async function dailyEventReferenceById(
- req: NextApiRequest,
+ { method, query, body, userId }: NextApiRequest,
res: NextApiResponse<DailyEventReferenceResponse>
) {
- const { method, query, body } = req;
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaDailyEventReferenceEditBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
- const userId = req.userId;
const userBookings = await prisma.booking.findMany({ where: { userId } });
- const userBookingIds = userBookings.map((booking) => booking.id);
+ const userBookingIds: number[] = userBookings.map((booking) => booking.id);
const userBookingDailyEventReferences = await prisma.dailyEventReference.findMany({
where: { bookingId: { in: userBookingIds } },
});
@@ -38,7 +36,7 @@ export async function dailyEventReferenceById(
* @swagger
* /event-references/{id}:
* get:
- * summary: Find a event reference by ID
+ * summary: Find a event reference
* parameters:
* - in: path
* name: id
diff --git a/pages/api/event-references/index.ts b/pages/api/event-references/index.ts
index 1168ccbda6e..bc19171de80 100644
--- a/pages/api/event-references/index.ts
+++ b/pages/api/event-references/index.ts
@@ -9,42 +9,29 @@ import {
schemaDailyEventReferenceReadPublic,
} from "@lib/validations/daily-event-reference";
-/**
- * @swagger
- * /event-references:
- * get:
- * summary: Find all daily event reference
- * tags:
- * - event-references
- * responses:
- * 200:
- * description: OK
- * 401:
- * description: Authorization information is missing or invalid.
- * 404:
- * description: No daily event references were found
- * post:
- * summary: Creates a new daily event reference
- * tags:
- * - event-references
- * responses:
- * 201:
- * description: OK, daily event reference created
- * 400:
- * description: Bad request. DailyEventReference body is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- */
async function createOrlistAllDailyEventReferences(
- req: NextApiRequest,
+ { method, body, userId }: NextApiRequest,
res: NextApiResponse<DailyEventReferencesResponse | DailyEventReferenceResponse>
) {
- const { method } = req;
- const userId = req.userId;
const userBookings = await prisma.booking.findMany({ where: { userId } });
const userBookingIds = userBookings.map((booking) => booking.id);
if (method === "GET") {
+ /**
+ * @swagger
+ * /event-references:
+ * get:
+ * summary: Find all daily event reference
+ * tags:
+ * - event-references
+ * responses:
+ * 200:
+ * description: OK
+ * 401:
+ * description: Authorization information is missing or invalid.
+ * 404:
+ * description: No daily event references were found
+ */
const data = await prisma.dailyEventReference.findMany({
where: { bookingId: { in: userBookingIds } },
});
@@ -59,7 +46,22 @@ async function createOrlistAllDailyEventReferences(
error,
});
} else if (method === "POST") {
- const safe = schemaDailyEventReferenceCreateBodyParams.safeParse(req.body);
+ /**
+ * @swagger
+ * /event-references:
+ * post:
+ * summary: Creates a new daily event reference
+ * tags:
+ * - event-references
+ * responses:
+ * 201:
+ * description: OK, daily event reference created
+ * 400:
+ * description: Bad request. DailyEventReference body is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
+ const safe = schemaDailyEventReferenceCreateBodyParams.safeParse(body);
if (!safe.success) throw new Error("Invalid request body");
const data = await prisma.dailyEventReference.create({ data: safe.data });
diff --git a/pages/api/event-types/[id].ts b/pages/api/event-types/[id].ts
index ebb440bd37a..0ece116d17b 100644
--- a/pages/api/event-types/[id].ts
+++ b/pages/api/event-types/[id].ts
@@ -10,87 +10,43 @@ import {
withValidQueryIdTransformParseInt,
} from "@lib/validations/shared/queryIdTransformParseInt";
-/**
- * @swagger
- * /event-types/{id}:
- * get:
- * summary: Find a eventType by ID
- * parameters:
- * - in: path
- * name: id
- * schema:
- * type: integer
- * required: true
- * description: Numeric ID of the eventType to get
- * security:
- * - ApiKeyAuth: []
- * tags:
- * - event-types
- * externalDocs:
- * url: https://docs.cal.com/event-types
- * responses:
- * 200:
- * description: OK
- * 401:
- * description: Authorization information is missing or invalid.
- * 404:
- * description: EventType was not found
- * patch:
- * summary: Edit an existing eventType
- * parameters:
- * - in: path
- * name: id
- * schema:
- * type: integer
- * required: true
- * description: Numeric ID of the eventType to edit
- * security:
- * - ApiKeyAuth: []
- * tags:
- * - event-types
- * externalDocs:
- * url: https://docs.cal.com/event-types
- * responses:
- * 201:
- * description: OK, eventType edited successfuly
- * 400:
- * description: Bad request. EventType body is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- * delete:
- * summary: Remove an existing eventType
- * parameters:
- * - in: path
- * name: id
- * schema:
- * type: integer
- * required: true
- * description: Numeric ID of the eventType to delete
- * security:
- * - ApiKeyAuth: []
- * tags:
- * - event-types
- * externalDocs:
- * url: https://docs.cal.com/event-types
- * responses:
- * 201:
- * description: OK, eventType removed successfuly
- * 400:
- * description: Bad request. EventType id is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- */
-export async function eventTypeById(req: NextApiRequest, res: NextApiResponse<EventTypeResponse>) {
- const { method, query, body } = req;
+export async function eventTypeById(
+ { method, query, body, userId }: NextApiRequest,
+ res: NextApiResponse<EventTypeResponse>
+) {
const safeQuery = schemaQueryIdParseInt.safeParse(query);
- const safeBody = schemaEventTypeBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
- const userId = req.userId;
const data = await prisma.eventType.findMany({ where: { userId } });
const userEventTypes = data.map((eventType) => eventType.id);
if (!userEventTypes.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" });
else {
switch (method) {
+ /**
+ * @swagger
+ * /event-types/{id}:
+ * get:
+ * summary: Find a eventType
+ * parameters:
+ * - in: path
+ * name: id
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric ID of the eventType to get
+ * security:
+ * - ApiKeyAuth: []
+ * tags:
+ * - event-types
+ * externalDocs:
+ * url: https://docs.cal.com/event-types
+ * responses:
+ * 200:
+ * description: OK
+ * 401:
+ * description: Authorization information is missing or invalid.
+ * 404:
+ * description: EventType was not found
+ */
case "GET":
await prisma.eventType
.findUnique({ where: { id: safeQuery.data.id } })
@@ -103,8 +59,34 @@ export async function eventTypeById(req: NextApiRequest, res: NextApiResponse<Ev
})
);
break;
-
+ /**
+ * @swagger
+ * /event-types/{id}:
+ * patch:
+ * summary: Edit an existing eventType
+ * parameters:
+ * - in: path
+ * name: id
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric ID of the eventType to edit
+ * security:
+ * - ApiKeyAuth: []
+ * tags:
+ * - event-types
+ * externalDocs:
+ * url: https://docs.cal.com/event-types
+ * responses:
+ * 201:
+ * description: OK, eventType edited successfuly
+ * 400:
+ * description: Bad request. EventType body is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
case "PATCH":
+ const safeBody = schemaEventTypeBodyParams.safeParse(body);
if (!safeBody.success) {
throw new Error("Invalid request body");
}
@@ -119,7 +101,32 @@ export async function eventTypeById(req: NextApiRequest, res: NextApiResponse<Ev
})
);
break;
-
+ /**
+ * @swagger
+ * /event-types/{id}:
+ * delete:
+ * summary: Remove an existing eventType
+ * parameters:
+ * - in: path
+ * name: id
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric ID of the eventType to delete
+ * security:
+ * - ApiKeyAuth: []
+ * tags:
+ * - event-types
+ * externalDocs:
+ * url: https://docs.cal.com/event-types
+ * responses:
+ * 201:
+ * description: OK, eventType removed successfuly
+ * 400:
+ * description: Bad request. EventType id is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
case "DELETE":
await prisma.eventType
.delete({ where: { id: safeQuery.data.id } })
diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts
index 4030e84186e..dad45eec42a 100644
--- a/pages/api/event-types/index.ts
+++ b/pages/api/event-types/index.ts
@@ -6,44 +6,28 @@ import { withMiddleware } from "@lib/helpers/withMiddleware";
import { EventTypeResponse, EventTypesResponse } from "@lib/types";
import { schemaEventTypeBodyParams, schemaEventTypePublic } from "@lib/validations/event-type";
-/**
- * @swagger
- * /event-types:
- * get:
- * summary: Find all event types
- * tags:
- * - event-types
- * externalDocs:
- * url: https://docs.cal.com/event-types
- * responses:
- * 200:
- * description: OK
- * 401:
- * description: Authorization information is missing or invalid.
- * 404:
- * description: No event types were found
- * post:
- * summary: Creates a new event type
- * tags:
- * - event-types
- * externalDocs:
- * url: https://docs.cal.com/event-types
- * responses:
- * 201:
- * description: OK, event type created
- * 400:
- * description: Bad request. EventType body is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- */
async function createOrlistAllEventTypes(
- req: NextApiRequest,
+ { method, body, userId }: NextApiRequest,
res: NextApiResponse<EventTypesResponse | EventTypeResponse>
) {
- const { method } = req;
- const userId = req.userId;
-
if (method === "GET") {
+ /**
+ * @swagger
+ * /event-types:
+ * get:
+ * summary: Find all event types
+ * tags:
+ * - event-types
+ * externalDocs:
+ * url: https://docs.cal.com/event-types
+ * responses:
+ * 200:
+ * description: OK
+ * 401:
+ * description: Authorization information is missing or invalid.
+ * 404:
+ * description: No event types were found
+ */
const data = await prisma.eventType.findMany({ where: { userId } });
const event_types = data.map((eventType) => schemaEventTypePublic.parse(eventType));
if (event_types) res.status(200).json({ event_types });
@@ -54,7 +38,24 @@ async function createOrlistAllEventTypes(
error,
});
} else if (method === "POST") {
- const safe = schemaEventTypeBodyParams.safeParse(req.body);
+ /**
+ * @swagger
+ * /event-types:
+ * post:
+ * summary: Creates a new event type
+ * tags:
+ * - event-types
+ * externalDocs:
+ * url: https://docs.cal.com/event-types
+ * responses:
+ * 201:
+ * description: OK, event type created
+ * 400:
+ * description: Bad request. EventType body is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
+ const safe = schemaEventTypeBodyParams.safeParse(body);
if (!safe.success) throw new Error("Invalid request body");
const data = await prisma.eventType.create({ data: { ...safe.data, userId } });
diff --git a/pages/api/memberships/[id].ts b/pages/api/memberships/[id].ts
index fa4c298be4d..0681a629a96 100644
--- a/pages/api/memberships/[id].ts
+++ b/pages/api/memberships/[id].ts
@@ -7,93 +7,45 @@ import type { MembershipResponse } from "@lib/types";
import { schemaMembershipBodyParams, schemaMembershipPublic } from "@lib/validations/membership";
import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString";
-/**
- * @swagger
- * /memberships/{userId}_{teamId}:
- * get:
- * summary: Find a membership by userID and teamID
- * parameters:
- * - in: path
- * name: userId
- * schema:
- * type: integer
- * required: true
- * description: Numeric userId of the membership to get
- * - in: path
- * name: teamId
- * schema:
- * type: integer
- * required: true
- * description: Numeric teamId of the membership to get
- * tags:
- * - memberships
- * responses:
- * 200:
- * description: OK
- * 401:
- * description: Authorization information is missing or invalid.
- * 404:
- * description: Membership was not found
- * patch:
- * summary: Edit an existing membership
- * parameters:
- * - in: path
- * name: userId
- * schema:
- * type: integer
- * required: true
- * description: Numeric userId of the membership to get
- * - in: path
- * name: teamId
- * schema:
- * type: integer
- * required: true
- * description: Numeric teamId of the membership to get
- * tags:
- * - memberships
- * responses:
- * 201:
- * description: OK, membership edited successfuly
- * 400:
- * description: Bad request. Membership body is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- * delete:
- * summary: Remove an existing membership
- * parameters:
- * - in: path
- * name: userId
- * schema:
- * type: integer
- * required: true
- * description: Numeric userId of the membership to get
- * - in: path
- * name: teamId
- * schema:
- * type: integer
- * required: true
- * description: Numeric teamId of the membership to get
- * tags:
- * - memberships
- * responses:
- * 201:
- * description: OK, membership removed successfuly
- * 400:
- * description: Bad request. Membership id is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- */
-export async function membershipById(req: NextApiRequest, res: NextApiResponse<MembershipResponse>) {
- const { method, query, body } = req;
+export async function membershipById(
+ { method, query, body, userId }: NextApiRequest,
+ res: NextApiResponse<MembershipResponse>
+) {
const safeQuery = schemaQueryIdAsString.safeParse(query);
- const safeBody = schemaMembershipBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
// This is how we set the userId and teamId in the query for managing compoundId.
const [paramUserId, teamId] = safeQuery.data.id.split("_");
- const userId = req.userId;
if (parseInt(paramUserId) !== userId) res.status(401).json({ message: "Unauthorized" });
else {
switch (method) {
+ /**
+ * @swagger
+ * /memberships/{userId}_{teamId}:
+ * get:
+ * summary: Find a membership by userID and teamID
+ * parameters:
+ * - in: path
+ * name: userId
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric userId of the membership to get
+ * - in: path
+ * name: teamId
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric teamId of the membership to get
+ * tags:
+ * - memberships
+ * responses:
+ * 200:
+ * description: OK
+ * 401:
+ * description: Authorization information is missing or invalid.
+ * 404:
+ * description: Membership was not found
+ */
case "GET":
await prisma.membership
.findUnique({
@@ -114,7 +66,36 @@ export async function membershipById(req: NextApiRequest, res: NextApiResponse<M
);
break;
+ /**
+ * @swagger
+ * /memberships/{userId}_{teamId}:
+ * patch:
+ * summary: Edit an existing membership
+ * parameters:
+ * - in: path
+ * name: userId
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric userId of the membership to get
+ * - in: path
+ * name: teamId
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric teamId of the membership to get
+ * tags:
+ * - memberships
+ * responses:
+ * 201:
+ * description: OK, membership edited successfuly
+ * 400:
+ * description: Bad request. Membership body is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
case "PATCH":
+ const safeBody = schemaMembershipBodyParams.safeParse(body);
if (!safeBody.success) {
throw new Error("Invalid request body");
}
@@ -138,6 +119,34 @@ export async function membershipById(req: NextApiRequest, res: NextApiResponse<M
);
break;
+ /**
+ * @swagger
+ * /memberships/{userId}_{teamId}:
+ * delete:
+ * summary: Remove an existing membership
+ * parameters:
+ * - in: path
+ * name: userId
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric userId of the membership to get
+ * - in: path
+ * name: teamId
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric teamId of the membership to get
+ * tags:
+ * - memberships
+ * responses:
+ * 201:
+ * description: OK, membership removed successfuly
+ * 400:
+ * description: Bad request. Membership id is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
case "DELETE":
await prisma.membership
.delete({
diff --git a/pages/api/memberships/index.ts b/pages/api/memberships/index.ts
index 137eaf48acc..2000ed84e3f 100644
--- a/pages/api/memberships/index.ts
+++ b/pages/api/memberships/index.ts
@@ -6,39 +6,26 @@ import { withMiddleware } from "@lib/helpers/withMiddleware";
import { MembershipResponse, MembershipsResponse } from "@lib/types";
import { schemaMembershipBodyParams, schemaMembershipPublic } from "@lib/validations/membership";
-/**
- * @swagger
- * /memberships:
- * get:
- * summary: Find all memberships
- * tags:
- * - memberships
- * responses:
- * 200:
- * description: OK
- * 401:
- * 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
- * 400:
- * description: Bad request. Membership body is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- */
async function createOrlistAllMemberships(
- req: NextApiRequest,
+ { method, body, userId }: NextApiRequest,
res: NextApiResponse<MembershipsResponse | MembershipResponse>
) {
- const { method } = req;
- const userId = req.userId;
if (method === "GET") {
+ /**
+ * @swagger
+ * /memberships:
+ * get:
+ * summary: Find all memberships
+ * tags:
+ * - memberships
+ * responses:
+ * 200:
+ * description: OK
+ * 401:
+ * description: Authorization information is missing or invalid.
+ * 404:
+ * description: No memberships were found
+ */
const data = await prisma.membership.findMany({ where: { userId } });
const memberships = data.map((membership) => schemaMembershipPublic.parse(membership));
if (memberships) res.status(200).json({ memberships });
@@ -49,7 +36,22 @@ async function createOrlistAllMemberships(
error,
});
} else if (method === "POST") {
- const safe = schemaMembershipBodyParams.safeParse(req.body);
+ /**
+ * @swagger
+ * /memberships:
+ * post:
+ * summary: Creates a new membership
+ * tags:
+ * - memberships
+ * responses:
+ * 201:
+ * description: OK, membership created
+ * 400:
+ * description: Bad request. Membership body is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
+ const safe = schemaMembershipBodyParams.safeParse(body);
if (!safe.success) throw new Error("Invalid request body");
const data = await prisma.membership.create({ data: { ...safe.data, userId } });
diff --git a/pages/api/payments/[id].ts b/pages/api/payments/[id].ts
index 90882e760ca..ebcaa0c504a 100644
--- a/pages/api/payments/[id].ts
+++ b/pages/api/payments/[id].ts
@@ -14,7 +14,7 @@ import {
* @swagger
* /payments/{id}:
* get:
- * summary: Find one of your own payments by ID
+ * summary: Find a payment
* parameters:
* - in: path
* name: id
@@ -32,11 +32,11 @@ import {
* 404:
* description: Payment was not found
*/
-export async function paymentById(req: NextApiRequest, res: NextApiResponse<PaymentResponse>) {
- const { method, query } = req;
+export async function paymentById(
+ { method, query, userId }: NextApiRequest,
+ res: NextApiResponse<PaymentResponse>
+) {
const safeQuery = schemaQueryIdParseInt.safeParse(query);
- const userId = req.userId;
-
if (safeQuery.success && method === "GET") {
const userWithBookings = await prisma.user.findUnique({
where: { id: userId },
diff --git a/pages/api/schedules/[id].ts b/pages/api/schedules/[id].ts
index d6645597a66..af63d8af2bb 100644
--- a/pages/api/schedules/[id].ts
+++ b/pages/api/schedules/[id].ts
@@ -10,64 +10,6 @@ import {
withValidQueryIdTransformParseInt,
} from "@lib/validations/shared/queryIdTransformParseInt";
-/**
- * @swagger
- * /schedules/{id}:
- * get:
- * summary: Find a schedule by ID
- * parameters:
- * - in: path
- * name: id
- * schema:
- * type: integer
- * required: true
- * description: Numeric ID of the schedule to get
- * tags:
- * - schedules
- * responses:
- * 200:
- * description: OK
- * 401:
- * description: Authorization information is missing or invalid.
- * 404:
- * description: Schedule was not found
- * patch:
- * summary: Edit an existing schedule
- * parameters:
- * - in: path
- * name: id
- * schema:
- * type: integer
- * required: true
- * description: Numeric ID of the schedule to edit
- * tags:
- * - schedules
- * responses:
- * 201:
- * description: OK, schedule edited successfuly
- * 400:
- * description: Bad request. Schedule body is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- * delete:
- * summary: Remove an existing schedule
- * parameters:
- * - in: path
- * name: id
- * schema:
- * type: integer
- * required: true
- * description: Numeric ID of the schedule to delete
- * tags:
- * - schedules
- * responses:
- * 201:
- * description: OK, schedule removed successfuly
- * 400:
- * description: Bad request. Schedule id is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- */
export async function scheduleById(req: NextApiRequest, res: NextApiResponse<ScheduleResponse>) {
const { method, query, body } = req;
const safeQuery = schemaQueryIdParseInt.safeParse(query);
@@ -79,6 +21,28 @@ export async function scheduleById(req: NextApiRequest, res: NextApiResponse<Sch
if (!userScheduleIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" });
else {
switch (method) {
+ /**
+ * @swagger
+ * /schedules/{id}:
+ * get:
+ * summary: Find a schedule
+ * parameters:
+ * - in: path
+ * name: id
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric ID of the schedule to get
+ * tags:
+ * - schedules
+ * responses:
+ * 200:
+ * description: OK
+ * 401:
+ * description: Authorization information is missing or invalid.
+ * 404:
+ * description: Schedule was not found
+ */
case "GET":
await prisma.schedule
.findUnique({ where: { id: safeQuery.data.id } })
@@ -92,6 +56,28 @@ export async function scheduleById(req: NextApiRequest, res: NextApiResponse<Sch
);
break;
+ /**
+ * @swagger
+ * /schedules/{id}:
+ * patch:
+ * summary: Edit an existing schedule
+ * parameters:
+ * - in: path
+ * name: id
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric ID of the schedule to edit
+ * tags:
+ * - schedules
+ * responses:
+ * 201:
+ * description: OK, schedule edited successfuly
+ * 400:
+ * description: Bad request. Schedule body is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
case "PATCH":
if (!safeBody.success) {
throw new Error("Invalid request body");
@@ -108,6 +94,28 @@ export async function scheduleById(req: NextApiRequest, res: NextApiResponse<Sch
);
break;
+ /**
+ * @swagger
+ * /schedules/{id}:
+ * delete:
+ * summary: Remove an existing schedule
+ * parameters:
+ * - in: path
+ * name: id
+ * schema:
+ * type: integer
+ * required: true
+ * description: Numeric ID of the schedule to delete
+ * tags:
+ * - schedules
+ * responses:
+ * 201:
+ * description: OK, schedule removed successfuly
+ * 400:
+ * description: Bad request. Schedule id is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
case "DELETE":
// Look for user to check if schedule is user's default
const user = await prisma.user.findUnique({ where: { id: userId } });
diff --git a/pages/api/schedules/index.ts b/pages/api/schedules/index.ts
index 29fe1603400..5da47e226c1 100644
--- a/pages/api/schedules/index.ts
+++ b/pages/api/schedules/index.ts
@@ -6,34 +6,6 @@ import { withMiddleware } from "@lib/helpers/withMiddleware";
import { ScheduleResponse, SchedulesResponse } from "@lib/types";
import { schemaScheduleBodyParams, schemaSchedulePublic } from "@lib/validations/schedule";
-/**
- * @swagger
- * /schedules:
- * get:
- * summary: Find all schedules
-
- * tags:
- * - schedules
- * responses:
- * 200:
- * description: OK
- * 401:
- * description: Authorization information is missing or invalid.
- * 404:
- * description: No schedules were found
- * post:
- * summary: Creates a new schedule
-
- * tags:
- * - schedules
- * responses:
- * 201:
- * description: OK, schedule created
- * 400:
- * description: Bad request. Schedule body is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- */
async function createOrlistAllSchedules(
req: NextApiRequest,
res: NextApiResponse<SchedulesResponse | ScheduleResponse>
@@ -42,6 +14,21 @@ async function createOrlistAllSchedules(
const userId = req.userId;
if (method === "GET") {
+ /**
+ * @swagger
+ * /schedules:
+ * get:
+ * summary: Find all schedules
+ * tags:
+ * - schedules
+ * responses:
+ * 200:
+ * description: OK
+ * 401:
+ * description: Authorization information is missing or invalid.
+ * 404:
+ * description: No schedules were found
+ */
const data = await prisma.schedule.findMany({ where: { userId } });
const schedules = data.map((schedule) => schemaSchedulePublic.parse(schedule));
if (schedules) res.status(200).json({ schedules });
@@ -52,6 +39,21 @@ async function createOrlistAllSchedules(
error,
});
} else if (method === "POST") {
+ /**
+ * @swagger
+ * /schedules:
+ * post:
+ * summary: Creates a new schedule
+ * tags:
+ * - schedules
+ * responses:
+ * 201:
+ * description: OK, schedule created
+ * 400:
+ * description: Bad request. Schedule body is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
const safe = schemaScheduleBodyParams.safeParse(req.body);
if (!safe.success) throw new Error("Invalid request body");
const data = await prisma.schedule.create({ data: { ...safe.data, userId } });
diff --git a/pages/api/selected-calendars/[id].ts b/pages/api/selected-calendars/[id].ts
index a8e1e7ab151..10fb737cf9e 100644
--- a/pages/api/selected-calendars/[id].ts
+++ b/pages/api/selected-calendars/[id].ts
@@ -10,101 +10,6 @@ import {
} from "@lib/validations/selected-calendar";
import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString";
-/**
- * @swagger
- * /selected-calendars/{userId}_{integration}_{externalId}:
- * get:
- * summary: Find a selected-calendar by userID and teamID
- * parameters:
- * - in: path
- * name: userId
- * schema:
- * type: integer
- * required: true
- * description: userId of the selected calendar to get
- * - in: path
- * name: externalId
- * schema:
- * type: string
- * required: true
- * description: externalId of the selected calendar to get
- * - in: path
- * name: integration
- * schema:
- * type: string
- * required: true
- * description: integration of the selected calendar to get
- * tags:
- * - selected-calendars
- * responses:
- * 200:
- * description: OK
- * 401:
- * description: Authorization information is missing or invalid.
- * 404:
- * description: SelectedCalendar was not found
- * patch:
- * summary: Edit an existing selected calendar
- * parameters:
- * - in: path
- * name: userId
- * schema:
- * type: integer
- * required: true
- * description: userId of the selected calendar to get
- * - in: path
- * name: externalId
- * schema:
- * type: string
- * required: true
- * description: externalId of the selected calendar to get
- * - in: path
- * name: integration
- * schema:
- * type: string
- * required: true
- * description: integration of the selected calendar to get
- * tags:
- * - selected-calendars
- * responses:
- * 201:
- * description: OK, selected-calendar edited successfuly
- * 400:
- * description: Bad request. SelectedCalendar body is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- * delete:
- * summary: Remove an existing selected-calendar
- * parameters:
- * - in: path
- * name: userId
- * schema:
- * type: integer
- * required: true
- * description: userId of the selected calendar to get
- * - in: path
- * name: externalId
- * schema:
- * type: integer
- * required: true
- * description: externalId of the selected-calendar to get
- * - in: path
- * name: integration
- * schema:
- * type: string
- * required: true
- * description: integration of the selected calendar to get
-
- * tags:
- * - selected-calendars
- * responses:
- * 201:
- * description: OK, selected-calendar removed successfuly
- * 400:
- * description: Bad request. SelectedCalendar id is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- */
export async function selectedCalendarById(
req: NextApiRequest,
res: NextApiResponse<SelectedCalendarResponse>
@@ -119,6 +24,40 @@ export async function selectedCalendarById(
if (userId !== parseInt(paramUserId)) res.status(401).json({ message: "Unauthorized" });
else {
switch (method) {
+ /**
+ * @swagger
+ * /selected-calendars/{userId}_{integration}_{externalId}:
+ * get:
+ * summary: Find a selected calendar
+ * parameters:
+ * - in: path
+ * name: userId
+ * schema:
+ * type: integer
+ * required: true
+ * description: userId of the selected calendar to get
+ * - in: path
+ * name: externalId
+ * schema:
+ * type: string
+ * required: true
+ * description: externalId of the selected calendar to get
+ * - in: path
+ * name: integration
+ * schema:
+ * type: string
+ * required: true
+ * description: integration of the selected calendar to get
+ * tags:
+ * - selected-calendars
+ * responses:
+ * 200:
+ * description: OK
+ * 401:
+ * description: Authorization information is missing or invalid.
+ * 404:
+ * description: SelectedCalendar was not found
+ */
case "GET":
await prisma.selectedCalendar
.findUnique({
@@ -140,6 +79,40 @@ export async function selectedCalendarById(
);
break;
+ /**
+ * @swagger
+ * /selected-calendars/{userId}_{integration}_{externalId}:
+ * patch:
+ * summary: Edit a selected calendar
+ * parameters:
+ * - in: path
+ * name: userId
+ * schema:
+ * type: integer
+ * required: true
+ * description: userId of the selected calendar to get
+ * - in: path
+ * name: externalId
+ * schema:
+ * type: string
+ * required: true
+ * description: externalId of the selected calendar to get
+ * - in: path
+ * name: integration
+ * schema:
+ * type: string
+ * required: true
+ * description: integration of the selected calendar to get
+ * tags:
+ * - selected-calendars
+ * responses:
+ * 201:
+ * description: OK, selected-calendar edited successfuly
+ * 400:
+ * description: Bad request. SelectedCalendar body is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
case "PATCH":
if (!safeBody.success) {
throw new Error("Invalid request body");
@@ -164,7 +137,40 @@ export async function selectedCalendarById(
})
);
break;
-
+ /**
+ * @swagger
+ * /selected-calendars/{userId}_{integration}_{externalId}:
+ * delete:
+ * summary: Remove a selected calendar
+ * parameters:
+ * - in: path
+ * name: userId
+ * schema:
+ * type: integer
+ * required: true
+ * description: userId of the selected calendar to get
+ * - in: path
+ * name: externalId
+ * schema:
+ * type: integer
+ * required: true
+ * description: externalId of the selected-calendar to get
+ * - in: path
+ * name: integration
+ * schema:
+ * type: string
+ * required: true
+ * description: integration of the selected calendar to get
+ * tags:
+ * - selected-calendars
+ * responses:
+ * 201:
+ * description: OK, selected-calendar removed successfuly
+ * 400:
+ * description: Bad request. SelectedCalendar id is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
case "DELETE":
await prisma.selectedCalendar
.delete({
diff --git a/pages/api/selected-calendars/index.ts b/pages/api/selected-calendars/index.ts
index c6e1b122d95..758d663b8f7 100644
--- a/pages/api/selected-calendars/index.ts
+++ b/pages/api/selected-calendars/index.ts
@@ -9,40 +9,26 @@ import {
schemaSelectedCalendarPublic,
} from "@lib/validations/selected-calendar";
-/**
- * @swagger
- * /selected-calendars:
- * get:
- * summary: Find all selected calendars
- * tags:
- * - selected-calendars
- * responses:
- * 200:
- * description: OK
- * 401:
- * description: Authorization information is missing or invalid.
- * 404:
- * description: No selected calendars were found
- * post:
- * summary: Creates a new selected calendar
- * tags:
- * - selected-calendars
- * responses:
- * 201:
- * description: OK, selected calendar created
- * 400:
- * description: Bad request. SelectedCalendar body is invalid.
- * 401:
- * description: Authorization information is missing or invalid.
- */
async function createOrlistAllSelectedCalendars(
- req: NextApiRequest,
+ { method, userId }: NextApiRequest,
res: NextApiResponse<SelectedCalendarsResponse | SelectedCalendarResponse>
) {
- const { method } = req;
- const userId = req.userId;
-
if (method === "GET") {
+ /**
+ * @swagger
+ * /selected-calendars:
+ * get:
+ * summary: Find all selected calendars
+ * tags:
+ * - selected-calendars
+ * responses:
+ * 200:
+ * description: OK
+ * 401:
+ * description: Authorization information is missing or invalid.
+ * 404:
+ * description: No selected calendars were found
+ */
const data = await prisma.selectedCalendar.findMany({ where: { userId } });
const selected_calendars = data.map((selected_calendar) =>
schemaSelectedCalendarPublic.parse(selected_calendar)
@@ -55,6 +41,32 @@ async function createOrlistAllSelectedCalendars(
error,
});
} else if (method === "POST") {
+ /**
+ * @swagger
+ * /selected-calendars:
+ * get:
+ * summary: Find all selected calendars
+ * tags:
+ * - selected-calendars
+ * responses:
+ * 200:
+ * description: OK
+ * 401:
+ * description: Authorization information is missing or invalid.
+ * 404:
+ * description: No selected calendars were found
+ * post:
+ * summary: Creates a new selected calendar
+ * tags:
+ * - selected-calendars
+ * responses:
+ * 201:
+ * description: OK, selected calendar created
+ * 400:
+ * description: Bad request. SelectedCalendar body is invalid.
+ * 401:
+ * description: Authorization information is missing or invalid.
+ */
const safe = schemaSelectedCalendarBodyParams.safeParse(req.body);
if (!safe.success) throw new Error("Invalid request body");
// Create new selectedCalendar connecting it to current userId
diff --git a/pages/api/teams/[id].ts b/pages/api/teams/[id].ts
index 0368a69f5c0..d3e971d4877 100644
--- a/pages/api/teams/[id].ts
+++ b/pages/api/teams/[id].ts
@@ -14,7 +14,7 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team";
* @swagger
* /teams/{id}:
* get:
- * summary: Find a team by ID
+ * summary: Find a team
* parameters:
* - in: path
* name: id
diff --git a/pages/api/users/[id].ts b/pages/api/users/[id].ts
index 4cea26e8e3f..58d0b41d366 100644
--- a/pages/api/users/[id].ts
+++ b/pages/api/users/[id].ts
@@ -14,7 +14,7 @@ import { schemaUserEditBodyParams, schemaUserReadPublic } from "@lib/validations
* @swagger
* /users/{id}:
* get:
- * summary: Find a user by ID, returns your user if regular user.
+ * summary: Find a user, returns your user if regular user.
* parameters:
* - in: path
* name: id
diff --git a/templates/endpoints/[id]/index.ts b/templates/endpoints/[id]/index.ts
index c3297459ac4..c9b1d851526 100644
--- a/templates/endpoints/[id]/index.ts
+++ b/templates/endpoints/[id]/index.ts
@@ -14,7 +14,7 @@ import {
* @swagger
* /v1/resources/{id}:
* get:
- * summary: Find a resource by ID
+ * summary: Find a resource
* parameters:
* - in: path
* name: id