Scheduling infrastructure for absolutely everyone.
fix: rename endpoints to be only 2 words max
Agusti Fernandez Pardod06a9488e4a3
diff --git a/README.md b/README.mdindex 17082202cd8..a9904ac3ff9 100644--- a/README.md+++ b/README.md@@ -127,9 +127,9 @@ We aim to provide a fully tested API for our peace of mind, this is accomplished| attendees | ✅ | ✅ | ✅ | ✅ | ✅ || availabilities | ✅ | ✅ | ✅ | ✅ | ✅ || booking-references | ✅ | ✅ | ✅ | ✅ | ✅ |-| daily-event-references | ✅ | ✅ | ✅ | ✅ | ✅ |+| event-references | ✅ | ✅ | ✅ | ✅ | ✅ || destination-calendars | ✅ | ✅ | ✅ | ✅ | ✅ |-| event-type-custom-inputs | ✅ | ✅ | ✅ | ✅ | ✅ |+| custom-inputs | ✅ | ✅ | ✅ | ✅ | ✅ || event-types | ✅ | ✅ | ✅ | ✅ | ✅ || memberships | ✅ | ✅ | ✅ | ✅ | ✅ || payments | ✅ | ✅ | ❌ | ❌ | ❌ |diff --git a/pages/api/attendees/[id].ts b/pages/api/attendees/[id].tsindex 01ae4f54492..b0bf73796fc 100644--- a/pages/api/attendees/[id].ts+++ b/pages/api/attendees/[id].ts@@ -19,14 +19,22 @@ export async function attendeeById(res.status(400).json({ error: safeQuery.error });throw new Error("Invalid request query", safeQuery.error);}- const userBookings = await prisma.booking.findMany({- where: { userId },- include: { attendees: true },- });- const attendees = userBookings.map((booking) => booking.attendees).flat();- const attendeeIds = attendees.map((attendee) => attendee.id);- // Here we make sure to only return attendee's of the user's own bookings.- if (!attendeeIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" });+ const userBookingsAttendeeIds = await prisma.booking+ // Find all user bookings, including attendees+ .findMany({+ where: { userId },+ include: { attendees: true },+ })+ .then(+ // Flatten and merge all the attendees in one array+ (bookings) =>+ bookings+ .map((bookings) => bookings.attendees) // Get the attendees IDs from user bookings+ .flat() // Needed to flatten the array of arrays of all bookings attendees+ .map((attendee) => attendee.id) // We only need the attendee IDs+ );+ // @note: Here we make sure to only return attendee's of the user's own bookings.+ if (!userBookingsAttendeeIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" });else {switch (method) {/**diff --git a/pages/api/bookings/[id].ts b/pages/api/bookings/[id].tsindex ddfa7a34ceb..0974bd55b16 100644--- a/pages/api/bookings/[id].ts+++ b/pages/api/bookings/[id].ts@@ -10,64 +10,6 @@ import {withValidQueryIdTransformParseInt,} from "@lib/validations/shared/queryIdTransformParseInt";-/**- * @swagger- * /bookings/{id}:- * get:- * summary: Find a booking by ID- * parameters:- * - in: path- * name: id- * schema:- * type: integer- * required: true- * description: Numeric ID of the booking to get- * tags:- * - bookings- * responses:- * 200:- * description: OK- * 401:- * description: Authorization information is missing or invalid.- * 404:- * description: Booking was not found- * patch:- * summary: Edit an existing booking- * parameters:- * - in: path- * name: id- * schema:- * type: integer- * required: true- * description: Numeric ID of the booking to edit- * tags:- * - bookings- * responses:- * 201:- * description: OK, booking edited successfuly- * 400:- * description: Bad request. Booking body is invalid.- * 401:- * description: Authorization information is missing or invalid.- * delete:- * summary: Remove an existing booking- * parameters:- * - in: path- * name: id- * schema:- * type: integer- * required: true- * description: Numeric ID of the booking to delete- * tags:- * - bookings- * responses:- * 201:- * description: OK, booking removed successfuly- * 400:- * description: Bad request. Booking id is invalid.- * 401:- * description: Authorization information is missing or invalid.- */export async function bookingById(req: NextApiRequest, res: NextApiResponse<BookingResponse>) {const { method, query, body } = req;const safeQuery = schemaQueryIdParseInt.safeParse(query);@@ -82,6 +24,28 @@ export async function bookingById(req: NextApiRequest, res: NextApiResponse<Bookif (!userBookingIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" });else {switch (method) {+ /**+ * @swagger+ * /bookings/{id}:+ * get:+ * summary: Find a booking by ID+ * parameters:+ * - in: path+ * name: id+ * schema:+ * type: integer+ * required: true+ * description: Numeric ID of the booking to get+ * tags:+ * - bookings+ * responses:+ * 200:+ * description: OK+ * 401:+ * description: Authorization information is missing or invalid.+ * 404:+ * description: Booking was not found+ */case "GET":await prisma.booking.findUnique({ where: { id: safeQuery.data.id } })@@ -94,10 +58,30 @@ export async function bookingById(req: NextApiRequest, res: NextApiResponse<Book}));break;-+ /**+ * @swagger+ * /bookings/{id}:+ * patch:+ * summary: Edit an existing booking+ * parameters:+ * - in: path+ * name: id+ * schema:+ * type: integer+ * required: true+ * description: Numeric ID of the booking to edit+ * tags:+ * - bookings+ * responses:+ * 201:+ * description: OK, booking edited successfuly+ * 400:+ * description: Bad request. Booking body is invalid.+ * 401:+ * description: Authorization information is missing or invalid.+ */case "PATCH":const safeBody = schemaBookingEditBodyParams.safeParse(body);-if (!safeBody.success) {throw new Error("Invalid request body");}@@ -115,7 +99,28 @@ export async function bookingById(req: NextApiRequest, res: NextApiResponse<Book}));break;-+ /**+ * @swagger+ * /bookings/{id}:+ * delete:+ * summary: Remove an existing booking+ * parameters:+ * - in: path+ * name: id+ * schema:+ * type: integer+ * required: true+ * description: Numeric ID of the booking to delete+ * tags:+ * - bookings+ * responses:+ * 201:+ * description: OK, booking removed successfuly+ * 400:+ * description: Bad request. Booking id is invalid.+ * 401:+ * description: Authorization information is missing or invalid.+ */case "DELETE":await prisma.booking.delete({ where: { id: safeQuery.data.id } })diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.tsindex 444fda94883..440bc876fbf 100644--- a/pages/api/bookings/index.ts+++ b/pages/api/bookings/index.ts@@ -6,6 +6,15 @@ import { withMiddleware } from "@lib/helpers/withMiddleware";import { BookingResponse, BookingsResponse } from "@lib/types";import { schemaBookingCreateBodyParams, schemaBookingReadPublic } from "@lib/validations/booking";+async function createOrlistAllBookings(+ req: NextApiRequest,+ res: NextApiResponse<BookingsResponse | BookingResponse>+) {+ const { method } = req;+ const userId = req.userId;++ if (method === "GET") {+/*** @swagger* /bookings:@@ -20,6 +29,21 @@ import { schemaBookingCreateBodyParams, schemaBookingReadPublic } from "@lib/val* 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 });+ else+ (error: Error) =>+ res.status(404).json({+ message: "No Bookings were found",+ error,+ });+ } else if (method === "POST") {++/**+ * @swagger+ * /bookings:* post:* summary: Creates a new booking* tags:@@ -32,24 +56,6 @@ import { schemaBookingCreateBodyParams, schemaBookingReadPublic } from "@lib/val* 401:* description: Authorization information is missing or invalid.*/-async function createOrlistAllBookings(- req: NextApiRequest,- res: NextApiResponse<BookingsResponse | BookingResponse>-) {- const { method } = req;- const userId = req.userId;-- if (method === "GET") {- const data = await prisma.booking.findMany({ where: { userId } });- const bookings = data.map((booking) => schemaBookingReadPublic.parse(booking));- if (bookings) res.status(200).json({ bookings });- else- (error: Error) =>- res.status(404).json({- message: "No Bookings were found",- error,- });- } else if (method === "POST") {const safe = schemaBookingCreateBodyParams.safeParse(req.body);if (!safe.success) throw new Error("Invalid request body");diff --git a/pages/api/event-type-custom-inputs/[id].ts b/pages/api/custom-inputs/[id].tssimilarity index 97%rename from pages/api/event-type-custom-inputs/[id].tsrename to pages/api/custom-inputs/[id].tsindex 0d84a2a6fb9..2860d9a525e 100644--- a/pages/api/event-type-custom-inputs/[id].ts+++ b/pages/api/custom-inputs/[id].ts@@ -15,7 +15,7 @@ import {/*** @swagger- * /event-type-custom-inputs/{id}:+ * /custom-inputs/{id}:* get:* summary: Find a eventTypeCustomInput by ID* parameters:@@ -26,7 +26,7 @@ import {* required: true* description: Numeric ID of the eventTypeCustomInput to get* tags:- * - event-type-custom-inputs+ * - custom-inputs* responses:* 200:* description: OK@@ -44,7 +44,7 @@ import {* required: true* description: Numeric ID of the eventTypeCustomInput to edit* tags:- * - event-type-custom-inputs+ * - custom-inputs* responses:* 201:* description: OK, eventTypeCustomInput edited successfuly@@ -62,7 +62,7 @@ import {* required: true* description: Numeric ID of the eventTypeCustomInput to delete* tags:- * - event-type-custom-inputs+ * - custom-inputs* responses:* 201:* description: OK, eventTypeCustomInput removed successfulydiff --git a/pages/api/event-type-custom-inputs/index.ts b/pages/api/custom-inputs/index.tssimilarity index 97%rename from pages/api/event-type-custom-inputs/index.tsrename to pages/api/custom-inputs/index.tsindex ac6c0f94cbf..ee1232d83cb 100644--- a/pages/api/event-type-custom-inputs/index.ts+++ b/pages/api/custom-inputs/index.ts@@ -11,11 +11,11 @@ import {/*** @swagger- * /event-type-custom-inputs:+ * /custom-inputs:* get:* summary: Find all eventTypeCustomInputs* tags:- * - event-type-custom-inputs+ * - custom-inputs* responses:* 200:* description: OK@@ -26,7 +26,7 @@ import {* post:* summary: Creates a new eventTypeCustomInput* tags:- * - event-type-custom-inputs+ * - custom-inputs* responses:* 201:* description: OK, eventTypeCustomInput createddiff --git a/pages/api/daily-event-references/[id].ts b/pages/api/event-references/[id].tssimilarity index 61%rename from pages/api/daily-event-references/[id].tsrename to pages/api/event-references/[id].tsindex 7f1b026e5c3..d0a31fcf111 100644--- a/pages/api/daily-event-references/[id].ts+++ b/pages/api/event-references/[id].ts@@ -13,64 +13,6 @@ import {withValidQueryIdTransformParseInt,} from "@lib/validations/shared/queryIdTransformParseInt";-/**- * @swagger- * /daily-event-references/{id}:- * get:- * summary: Find a daily event reference by ID- * parameters:- * - in: path- * name: id- * schema:- * type: integer- * required: true- * description: Numeric ID of the daily event reference to get- * tags:- * - daily-event-references- * responses:- * 200:- * description: OK- * 401:- * description: Authorization information is missing or invalid.- * 404:- * description: DailyEventReference was not found- * patch:- * summary: Edit an existing daily event reference- * parameters:- * - in: path- * name: id- * schema:- * type: integer- * required: true- * description: Numeric ID of the daily event reference to edit- * tags:- * - daily-event-references- * responses:- * 201:- * description: OK, dailyEventReference edited successfuly- * 400:- * description: Bad request. DailyEventReference body is invalid.- * 401:- * description: Authorization information is missing or invalid.- * delete:- * summary: Remove an existing daily event reference- * parameters:- * - in: path- * name: id- * schema:- * type: integer- * required: true- * description: Numeric ID of the daily event reference to delete- * tags:- * - daily-event-references- * responses:- * 201:- * description: OK, dailyEventReference removed successfuly- * 400:- * description: Bad request. DailyEventReference id is invalid.- * 401:- * description: Authorization information is missing or invalid.- */export async function dailyEventReferenceById(req: NextApiRequest,res: NextApiResponse<DailyEventReferenceResponse>@@ -92,6 +34,28 @@ export async function dailyEventReferenceById(res.status(401).json({ message: "Unauthorized" });else {switch (method) {+ /**+ * @swagger+ * /event-references/{id}:+ * get:+ * summary: Find a event reference by ID+ * parameters:+ * - in: path+ * name: id+ * schema:+ * type: integer+ * required: true+ * description: Numeric ID of the event reference to get+ * tags:+ * - event-references+ * responses:+ * 200:+ * description: OK+ * 401:+ * description: Authorization information is missing or invalid.+ * 404:+ * description: EventReference was not found+ */case "GET":await prisma.dailyEventReference.findUnique({ where: { id: safeQuery.data.id } })@@ -105,6 +69,28 @@ export async function dailyEventReferenceById();break;+ /**+ * @swagger+ * /event-references/{id}:+ * patch:+ * summary: Edit an existing event reference+ * parameters:+ * - in: path+ * name: id+ * schema:+ * type: integer+ * required: true+ * description: Numeric ID of the event reference to edit+ * tags:+ * - event-references+ * responses:+ * 201:+ * description: OK, EventReference edited successfuly+ * 400:+ * description: Bad request. EventReference body is invalid.+ * 401:+ * description: Authorization information is missing or invalid.+ */case "PATCH":if (!safeBody.success) {throw new Error("Invalid request body");@@ -121,6 +107,28 @@ export async function dailyEventReferenceById();break;+ /**+ * @swagger+ * /event-references/{id}:+ * delete:+ * summary: Remove an existing event reference+ * parameters:+ * - in: path+ * name: id+ * schema:+ * type: integer+ * required: true+ * description: Numeric ID of the event reference to delete+ * tags:+ * - event-references+ * responses:+ * 201:+ * description: OK, EventReference removed successfuly+ * 400:+ * description: Bad request. EventReference id is invalid.+ * 401:+ * description: Authorization information is missing or invalid.+ */case "DELETE":await prisma.dailyEventReference.delete({diff --git a/pages/api/daily-event-references/index.ts b/pages/api/event-references/index.tssimilarity index 96%rename from pages/api/daily-event-references/index.tsrename to pages/api/event-references/index.tsindex c129eef677a..1168ccbda6e 100644--- a/pages/api/daily-event-references/index.ts+++ b/pages/api/event-references/index.ts@@ -11,11 +11,11 @@ import {/*** @swagger- * /daily-event-references:+ * /event-references:* get:* summary: Find all daily event reference* tags:- * - daily-event-references+ * - event-references* responses:* 200:* description: OK@@ -26,7 +26,7 @@ import {* post:* summary: Creates a new daily event reference* tags:- * - daily-event-references+ * - event-references* responses:* 201:* description: OK, daily event reference created