Add PUT /users/:id endpoint to update a user - #116
Open
volodymyrlp wants to merge 3 commits into
Open
Conversation
Returns the updated user, or undefined when the id is unknown, so the route layer can distinguish a successful update from a missing user. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Validates name and email before the store lookup so a missing field returns 400 even for an existing id; a lookup miss returns 404. Follows the existing users route conventions and goes through db/store.js. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Covers the approved plan, model choice, commit split, and review. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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 an update a user endpoint:
PUT /users/:id.db/store.js: newupdateUser(id, { name, email })helper — returns the updated user, orundefinedfor an unknown id.routes/users.js: newPUT /users/:idroute — parses the id, validates the body, calls the store helper, maps to200/404.NOTES.md: plan, model choice, commit split, and review write-up.Why
The users resource could list, fetch, and create but not update. This fills the gap, following existing route conventions and going through
db/store.js.Behaviour
name+email→200with the updated user404 { "error": "User not found" }400 { "error": "name and email are required" }(validation runs before the store lookup)What to test
200)PUT /users/9999with a valid body →404, no crashPUT /users/1with onlyname→400npm test(9 passing),npm run lint(clean)