Skip to content

Add PUT /users/:id endpoint to update a user - #13

Open
aruizacevedo wants to merge 5 commits into
mate-academy:mainfrom
aruizacevedo:feat/update-user-endpoint
Open

Add PUT /users/:id endpoint to update a user#13
aruizacevedo wants to merge 5 commits into
mate-academy:mainfrom
aruizacevedo:feat/update-user-endpoint

Conversation

@aruizacevedo

Copy link
Copy Markdown

Summary

  • Adds PUT /users/:id to update an existing user's name and email
  • Returns 400 on missing or whitespace-only fields, 404 when the user doesn't exist
  • Fixes whitespace-only validation gap in POST /users as well, for consistency
  • Fixes a high-severity npm vulnerability via npm audit fix

What changed

db/store.js — new updateUser(id, { name, email }) helper that mutates the record in place and returns undefined for unknown ids (so the route can 404 cleanly).

routes/users.js — new PUT /:id handler; also added an isBlank helper 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/1 with { name: "Ada L.", email: "ada.l@example.com" } → 200 with updated fields
  • PUT /users/9999 with a valid body → 404
  • PUT /users/1 with only name (missing email) → 400
  • PUT /users/1 with { name: " ", email: "x@x.com" } → 400 (whitespace fix)
  • npm test → all 9 tests green

🤖 Generated with Claude Code

aruizacevedo and others added 5 commits June 26, 2026 17:10
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant