diff --git a/pages/api/attendees/[id].ts b/pages/api/attendees/[id].ts index 3eba0891f2..03133bf526 100644 --- a/pages/api/attendees/[id].ts +++ b/pages/api/attendees/[id].ts @@ -100,7 +100,8 @@ export async function attendeeById(req: NextApiRequest, res: NextApiResponse 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)) { + if (!attendeeIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" }); + else { switch (method) { case "GET": await prisma.attendee @@ -151,7 +152,7 @@ export async function attendeeById(req: NextApiRequest, res: NextApiResponse booking.id).flat(); - if (userBookingIds.includes(bookingId)) { + if (!userBookingIds.includes(bookingId)) res.status(401).json({ message: "Unauthorized" }); + else { delete safe.data.bookingId; const noBookingId = safe.data; const data = await prisma.attendee.create({ @@ -99,7 +100,7 @@ async function createOrlistAllAttendees( error, }); } - } else res.status(401).json({ message: "Unauthorized" }); + } } else res.status(405).json({ message: `Method ${method} not allowed` }); }