feat: api routes for bookings and events query#40
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
TheMythologist
left a comment
There was a problem hiding this comment.
Read through the comments and update this branch! Feel free to PM me if you have any questions
There was a problem hiding this comment.
Could you refactor to use request.nextUrl.searchParams instead? No need to cast it to a new URL
https://nextjs.org/docs/app/api-reference/file-conventions/route#url-query-parameters
src/app/api/bookings/route.ts
Outdated
| const bookingName = url.searchParams.get('bookingName'); | ||
| const start = url.searchParams.get('start'); | ||
| const end = url.searchParams.get('end'); | ||
| const venue = url.searchParams.get('venue'); | ||
| const organisation = url.searchParams.get('organisation'); |
There was a problem hiding this comment.
Use zod to validate the type and searchParams, casting it to a Date or number if necessary.
For an example, refer to https://github.com/usdevs/NUSCweb/blob/main/src/lib/schema/booking.ts
src/app/api/bookings/route.ts
Outdated
| const venue = url.searchParams.get('venue'); | ||
| const organisation = url.searchParams.get('organisation'); | ||
|
|
||
| let bookings = await getBookings(); |
There was a problem hiding this comment.
Instead of getting all bookings and then filter manually on our server, instead pass the filters through Prisma and only return the necessary bookings
Refer to https://www.prisma.io/docs/orm/prisma-client/queries/filtering-and-sorting for documentation
src/app/api/events/route.ts
Outdated
| const url = new URL(request.url); | ||
|
|
||
| const orgName = url.searchParams.get('orgName'); | ||
| const start = url.searchParams.get('start'); | ||
| const end = url.searchParams.get('end'); | ||
| const venue = url.searchParams.get('venue'); | ||
| const organisation = url.searchParams.get('organisation'); | ||
|
|
||
| let events = await getEvents(); |
There was a problem hiding this comment.
Same comments here as the previous file
Resolves #16