Add PUT /users/:id to update a user - #149
Conversation
Follows the existing getUserById/createUser style: looks the user up by id and returns null when it doesn't exist, so callers can decide how to respond, rather than throwing. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016bAMXd9DFUQXzUVESdPZ7e
Validates name/email are present (400), same as POST, then 404s if the id doesn't match a user. Turns tests/update-user.test.js green. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016bAMXd9DFUQXzUVESdPZ7e
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016bAMXd9DFUQXzUVESdPZ7e
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved. The PUT /users/:id endpoint correctly validates name and email (returning 400 on missing/invalid input), updates via store.updateUser, and returns 404 when the user doesn’t exist, then 200 with the updated user on success. The updateUser implementation follows the established store pattern, returning null when no match is found and mutating the existing user object appropriately. NOTES.md provides a clear plan, model choice, and self-review rationale, meeting the documentation expectations.
Minor suggestion: there’s some duplicated validation logic between POST and PUT; consider extracting a small helper or middleware to DRY this up. Great work aligning with the existing codebase conventions and covering the key behaviors tested.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Summary
updateUser(id, { name, email })todb/store.js, mirroring the existinggetUserById/createUserstyle (returnsnullwhen the id doesn't match a user).PUT /users/:idtoroutes/users.js: validatesname/emailare present (400, same pattern asPOST /), then 404s if the id doesn't exist, otherwise updates and returns the user (200).NOTES.mdcovering the plan, model choice, commit split, and self-review findings.What to test
PUT /users/:idwith an existing id and both fields → 200 with the updatedname/email.PUT /users/9999with both fields → 404.PUT /users/:idwith onlyname(or onlyemail) → 400, even for an id that exists.Test plan
npm test— all 9 tests pass, includingtests/update-user.test.js(previously red) and the pre-existingtests/users.test.js/tests/notes.test.js.POST /noted and left as-is (mirrors existing pattern).🤖 Generated with Claude Code
https://claude.ai/code/session_016bAMXd9DFUQXzUVESdPZ7e