fix: rename endpoints to be only 2 words max
This commit is contained in:
@@ -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 | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
|
||||
@@ -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) {
|
||||
/**
|
||||
|
||||
+66
-61
@@ -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<Book
|
||||
if (!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 } })
|
||||
|
||||
+24
-18
@@ -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");
|
||||
|
||||
|
||||
@@ -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 successfuly
|
||||
@@ -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 created
|
||||
@@ -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({
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user