Add PUT /users/:id (update a user) - #18
Open
tskaara wants to merge 6 commits into
Open
Conversation
added 6 commits
July 3, 2026 08:33
Looks up a user by id and updates its name/email, returning undefined when the id doesn't exist so callers can 404 without a second lookup.
Validates name/email before touching the store (matching POST /users), then 404s via store.updateUser if the id doesn't exist.
Explains the approved plan, model choice, commit split, and what self-review confirmed for the update-user endpoint.
Self-review flagged that truthy-only validation let non-string values (numbers, booleans) through and get stored, violating the user shape.
Corrects the review section, which previously said the review was clean, now that a follow-up pass caught and fixed a real gap.
Empty commit to re-run GitHub Actions now that it's enabled.
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.
Summary
updateUser(id, { name, email })todb/store.js, mirroringcreateUser's style: looks up the user by id and mutates it in place, returningundefinedwhen the id doesn't exist.PUT /users/:idtoroutes/users.js: validatesname/emailare present and are strings (400 otherwise), then 404s if the id doesn't exist, otherwise returns the updated user.idis only ever taken from the URL param, never the request body, so a client can't reassign a user's id.NOTES.mdexplaining the plan, model choice, commit split, and what two rounds of self-review caught.Test plan
npm test— all 9 tests pass, including the three grading tests intests/update-user.test.js(200 update, 404 unknown id, 400 missing field) and bothNOTES.mdtests.npm run lint— clean.npm start, thencurl -X PUT localhost:3000/users/1 -H "Content-Type: application/json" -d '{"name":"X","email":"y@z.com"}'to confirm the not-found path (/users/9999) and validation path (missing or non-string field) both return the right status codes.🤖 Generated with Claude Code