Add PUT /users/:id (update a user) - #28
Open
franzyellow wants to merge 4 commits into
Open
Conversation
added 4 commits
July 9, 2026 14:46
Mirrors getUserById's lookup and createUser's destructured params. Mutates in place and returns undefined when the id doesn't exist, so callers can reuse the existing !user not-found check.
Validates name/email before touching the store, same order as POST, so a bad body reports 400 even when the target id doesn't exist. Returns 404 via store.updateUser's undefined sentinel otherwise.
Self-review caught updateUser re-implementing the same id lookup getUserById already does, risking drift if the lookup logic changes.
Explains the approved plan, model choice, commit split, and what self-review caught, per the assignment's deliverables.
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
PUT /users/:idto update an existing user'sname/email, following the existing GET/POST route patternsupdateUser(id, { name, email })todb/store.jsas the data-access helper for the new route!name || !email→ 400), and returns 404 when the id doesn't exist, rather than crashingNOTES.mddocumenting the plan, model choice (Sonnet), commit split, and what self-review caughtWhy
This is the course's "ship a real change end to end" exercise — implementing the update-user endpoint that
tests/update-user.test.jsalready specifies, without editing that test file.What to test
npm test— all 9 tests pass, including the threeupdate-user.test.jscases and the twoNOTES.mdchecksPUT /users/:idwith a full valid body on an existing id →200with the updated userPUT /users/:idon a nonexistent id →404, not a crashPUT /users/:idwith a missing field (e.g. onlyname) →400🤖 Generated with Claude Code