Skip to content

Add PUT /users/:id (update a user) - #18

Open
tskaara wants to merge 6 commits into
mate-academy:mainfrom
tskaara:update-user-endpoint
Open

Add PUT /users/:id (update a user)#18
tskaara wants to merge 6 commits into
mate-academy:mainfrom
tskaara:update-user-endpoint

Conversation

@tskaara

@tskaara tskaara commented Jul 3, 2026

Copy link
Copy Markdown

Summary

  • Adds updateUser(id, { name, email }) to db/store.js, mirroring createUser's style: looks up the user by id and mutates it in place, returning undefined when the id doesn't exist.
  • Adds PUT /users/:id to routes/users.js: validates name/email are present and are strings (400 otherwise), then 404s if the id doesn't exist, otherwise returns the updated user.
  • id is only ever taken from the URL param, never the request body, so a client can't reassign a user's id.
  • Adds NOTES.md explaining 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 in tests/update-user.test.js (200 update, 404 unknown id, 400 missing field) and both NOTES.md tests.
  • npm run lint — clean.
  • Manual check (optional): npm start, then curl -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

Thomas Eklo Skaara 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.
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