Add PUT /users/:id endpoint to update a user - #142
Open
kfhawas wants to merge 2 commits into
Open
Conversation
Adds an update-user route alongside the existing users actions. The route validates that name and email are present (400 otherwise), delegates to a new store.updateUser helper, and returns 404 when no user has that id. store.updateUser reuses getUserById and mutates the matched record in place, returning undefined for an unknown id so the route can branch on it the same way GET /users/:id does. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019xjAHNy1M6tER5BtovcVb1
NOTES.md is the write-up deliverable for this task: it records the approved plan, model choice, commit-split rationale, and what the self-review caught. It's kept as its own commit, separate from the endpoint code, since it's documentation rather than part of the feature's logic. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KPzJqMgRQzUCwFcQoGfqyw
mateacademy-ai-mentor
approved these changes
Sep 8, 2026
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am approving your solution. The PUT /users/:id endpoint correctly validates name and email, returns 404 for unknown users, and responds with the updated user on success, matching the existing patterns. The db/store.js updateUser helper reuses getUserById, updates only allowed fields, and returns undefined when the user is not found, aligning with the repository’s conventions. NOTES.md is clear and covers the plan, model choice, commit rationale, and review findings.
Minor suggestions (non-blocking):
- Consider trimming inputs and optionally adding basic email format checks to prevent accepting whitespace-only or malformed emails.
- For clarity, you could explicitly handle non-numeric
:id(e.g.,isNaN) before lookup and decide whether to return 400 or 404 per your API conventions.
Overall, well done—clean, consistent, and aligned with the requirements.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
PUT /users/:idto update an existing user'snameandemail.db/store.js— newupdateUser(id, { name, email })helper. ReusesgetUserByIdand returnsundefinedfor an unknown id, mirroring howgetUserByIdalready signals "not found".routes/users.js— newPUT /:idroute. Validates thatnameandemailare present (400 otherwise, same response shape asPOST /users), then returns 404 if the store reports no such user, else 200 with the updated user.Behavior notes
POST /usersstyle rather than inventing a new convention for this route.nameandemailare destructured from the body, so a client cannot overwriteidthrough the request payload.Number("abc")isNaN, which never matches a real id, so the request falls through to 404.Testing
npm test— 9/9 passing, including the three cases for this endpoint (successful update, 404 for unknown id, 400 for a missing field).Commits
Add PUT /users/:id endpoint to update a user— the feature (store helper + route together, since the route is broken without the helper).Add NOTES.md write-up deliverable— the task write-up, kept separate from the endpoint logic.🤖 Generated with Claude Code