Add PUT /users/:id endpoint to update a user - #13
Open
aruizacevedo wants to merge 5 commits into
Open
Conversation
The upcoming PUT /users/:id endpoint needs a data-layer operation that locates a user by id, overwrites name and email, and returns the updated record — or undefined when the id doesn't exist, so the route can 404 cleanly. Follows the same pattern as getUserById and createUser. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Exposes the update endpoint: validates that name and email are both present (400 on a missing field), delegates to store.updateUser, and returns 404 when the id doesn't exist rather than crashing. Follows the same validation and not-found patterns as the existing POST and GET /:id handlers. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The previous !name || !email guard treated " " as a valid value, letting a user's name or email be silently overwritten with blanks. Add an isBlank helper (checks for missing, non-string, or trim-empty) and apply it in both POST and PUT so validation is consistent across the users resource. Surfaced by the pre-push code review. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Required deliverable explaining the decisions behind the change: why the plan was approved as-is, the opusplan model choice, how commits were split by logical dependency, and what the code review caught (whitespace validation fix) vs. what was left out of scope. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Resolves 1 high-severity vulnerability flagged on npm install. Co-Authored-By: Claude Sonnet 4.6 <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.
Summary
PUT /users/:idto update an existing user'snameandemailPOST /usersas well, for consistencynpm audit fixWhat changed
db/store.js— newupdateUser(id, { name, email })helper that mutates the record in place and returnsundefinedfor unknown ids (so the route can 404 cleanly).routes/users.js— newPUT /:idhandler; also added anisBlankhelper and applied it to both POST and PUT so whitespace-only strings (e.g." ") are rejected with 400 rather than accepted silently.NOTES.md— required course deliverable documenting plan, model choice, commit split, and review findings.What a reviewer should test
PUT /users/1with{ name: "Ada L.", email: "ada.l@example.com" }→ 200 with updated fieldsPUT /users/9999with a valid body → 404PUT /users/1with onlyname(missingemail) → 400PUT /users/1with{ name: " ", email: "x@x.com" }→ 400 (whitespace fix)npm test→ all 9 tests green🤖 Generated with Claude Code