Skip to content

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

Open
8kb wants to merge 3 commits into
mate-academy:mainfrom
8kb:feature/update-user-endpoint
Open

Add PUT /users/:id to update a user#149
8kb wants to merge 3 commits into
mate-academy:mainfrom
8kb:feature/update-user-endpoint

Conversation

@8kb

@8kb 8kb commented Sep 10, 2026

Copy link
Copy Markdown

Summary

  • Adds updateUser(id, { name, email }) to db/store.js, mirroring the existing getUserById/createUser style (returns null when the id doesn't match a user).
  • Adds PUT /users/:id to routes/users.js: validates name/email are present (400, same pattern as POST /), then 404s if the id doesn't exist, otherwise updates and returns the user (200).
  • Adds NOTES.md covering the plan, model choice, commit split, and self-review findings.

What to test

  • Valid update: PUT /users/:id with an existing id and both fields → 200 with the updated name/email.
  • Unknown id: PUT /users/9999 with both fields → 404.
  • Missing field: PUT /users/:id with only name (or only email) → 400, even for an id that exists.

Test plan

  • npm test — all 9 tests pass, including tests/update-user.test.js (previously red) and the pre-existing tests/users.test.js / tests/notes.test.js.
  • Self-reviewed the diff before pushing — no correctness issues found; one minor, non-blocking validation duplication with POST / noted and left as-is (mirrors existing pattern).

🤖 Generated with Claude Code

https://claude.ai/code/session_016bAMXd9DFUQXzUVESdPZ7e

8kb and others added 3 commits September 10, 2026 18:06
Follows the existing getUserById/createUser style: looks the user up
by id and returns null when it doesn't exist, so callers can decide
how to respond, rather than throwing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016bAMXd9DFUQXzUVESdPZ7e
Validates name/email are present (400), same as POST, then 404s if
the id doesn't match a user. Turns tests/update-user.test.js green.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016bAMXd9DFUQXzUVESdPZ7e

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Your solution is approved. The PUT /users/:id endpoint correctly validates name and email (returning 400 on missing/invalid input), updates via store.updateUser, and returns 404 when the user doesn’t exist, then 200 with the updated user on success. The updateUser implementation follows the established store pattern, returning null when no match is found and mutating the existing user object appropriately. NOTES.md provides a clear plan, model choice, and self-review rationale, meeting the documentation expectations.

Minor suggestion: there’s some duplicated validation logic between POST and PUT; consider extracting a small helper or middleware to DRY this up. Great work aligning with the existing codebase conventions and covering the key behaviors tested.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

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.

2 participants