Add PUT /users/:id endpoint to update a user - #102
Closed
julien-vidal wants to merge 6 commits into
Closed
Conversation
added 6 commits
August 24, 2026 15:01
Mirrors getUserById/createUser's shape so routes stay thin. Returns undefined for an unknown id, matching getUserById's contract.
…ling Validates name (non-empty string) and email (basic shape) before the lookup, so a bad body is rejected the same way whether or not the id exists. Turns tests/update-user.test.js green.
Adds cases the fixed grading file doesn't check: non-numeric id, malformed email, empty body, whitespace-only name, non-string fields, and that the update actually persists to the store (not just the response) without reassigning the user's id.
Covers the approved plan and the edit made to it, model choice, commit split, and what self-review caught.
isValidEmail regex-tested the raw value while the store write trimmed it, so a valid email with incidental surrounding whitespace was rejected with 400 instead of being accepted and stored trimmed.
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 })helper indb/store.js, matching the shape of the existinggetUserById/createUserhelpers; returnsundefinedfor an unknown id.PUT /users/:idinroutes/users.js: validatesname(non-empty string) andemail(basic shape, whitespace trimmed before both validation and storage) before the id lookup, then 404s if the user doesn't exist, or returns the updated user with 200.tests/update-user.edge-cases.test.jscovering cases the fixed grading file (tests/update-user.test.js, left untouched) doesn't: non-numeric id, malformed/whitespace-padded email, empty body, whitespace-only name, non-string fields, that the update actually persists to the store, and that the id is never reassigned.NOTES.mdwith the plan, model choice, commit rationale, and self-review notes (including a bug caught during review: email validation ran a regex against the untrimmed value while storage trimmed it, so a valid email with incidental surrounding whitespace was wrongly rejected — fixed by trimming before validating).Test plan
npm test— 18/18 passing, including all three tests intests/update-user.test.jsnpm run lint— cleanPUT /users/1with a valid body returns 200 and the updated fieldsPUT /users/9999returns 404PUT /users/1with a missing/invalid field returns 400🤖 Generated with Claude Code