K1 5 create user schema and endpoints#6
K1 5 create user schema and endpoints#6RishanBaweja wants to merge 2 commits intohack4impact-calpoly:developfrom
Conversation
kaseyliu
left a comment
There was a problem hiding this comment.
Looks great overall! Left a few nitpicky comments, lmk if you are confused about them
| import mongoose from "mongoose"; | ||
|
|
||
| // Get a specific user, finding the user by their userID | ||
| export async function GET(_req: Request, { params }: { params: { id: string } }) { |
There was a problem hiding this comment.
Was there a reason for using the normal Request vs NextRequest? We don't really need NextRequest, but lowkey I'd say just use it in case we need the functionality from it later (you can change the other ones to use NextRequest too)
|
|
||
| const { id } = params; | ||
|
|
||
| const user = await User.findById(id).lean(); |
There was a problem hiding this comment.
const user = await User.findById(id).lean(); You should probably move this to under your check for if the id is valid, so that this doesn't error (same for PUT)
| // Get a specific user, finding the user by their userID | ||
| export async function GET(_req: Request, { params }: { params: { id: string } }) { | ||
| try { | ||
| await connectDB(); |
There was a problem hiding this comment.
await connectDB();You could move this under your check for if the id is valid too, to avoid connecting if there's no id (same for PUT)
|
|
||
| const { id } = params; | ||
| const changes = await req.json(); | ||
|
|
There was a problem hiding this comment.
It would be good to add an id is valid check here too, like you did in GET
| const body = await req.json(); | ||
| const user = await User.create(body); | ||
| return NextResponse.json(user, { status: 201 }); | ||
| } catch (err: any) { |
There was a problem hiding this comment.
nit: could add console.error messages for all of these!
Developer: Rishan Baweja
Closes #5
Pull Request Summary
Added the requested endpoints (retrieve all users, add user, retrieve a specific user, and update a specific user).
I did the updating and retrieving a specific user by their UUID
Modifications
I changed the userSchema file and updated it to match the specification, and I did the same for the Atlas preview. Additionally I added and changed the route files so that they would work for the requested API endpoints.
Testing Considerations
I tested the four API endpoints using Postman, and they worked on my end. My screenshots are below for it
Pull Request Checklist
Screenshots/Screencast