Add PUT /users/:id endpoint to update a user - #118
Conversation
Validates required fields, returns 404 for unknown users instead of crashing, and goes through a new db/store.js updateUser helper to stay consistent with the existing GET/POST handlers. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0145ufxzBfh7NnfMRL4yYMvp
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your implementation is approved. The db/store.js correctly implements the updateUser function following the existing pattern — it reuses getUserById for lookups, returns null when a user isn't found, and mutates only the allowed fields. The NOTES.md documentation is thorough and covers all required topics (plan, model choice, commit strategy, and review findings). Based on the individual file review, the routes/users.js endpoint properly validates required fields (returning 400), returns 404 for unknown users, and returns 200 with the updated user on success. The data access properly routes through db/store.js as required. All components work together correctly to fulfill the update user feature.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
What: Adds
PUT /users/:idto update an existing user'snameandemail. Validates that both fields are present (400 with a clear error if not), returns 404 if the user doesn't exist, and routes the actual mutation through a newupdateUser(id, { name, email })helper indb/store.js— keeping data access centralized there like the existingGET/POSThandlers.Why: The users resource could be created and read but not updated — this was the missing CRUD piece, requested to complete the resource.
What to test:
PUT /users/:idwith a validname/emailon an existing user →200with the updated user returned.PUT /users/:idon a non-existent (or non-numeric) id →404, no crash.PUT /users/:idwith a missingnameoremail→400with an error message.GET /users,GET /users/:id,POST /usersbehavior unchanged.npm test— full suite (9 tests) passes;npx eslintclean.