Skip to content

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

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

Add PUT /users/:id endpoint to update a user#116
volodymyrlp wants to merge 3 commits into
mate-academy:mainfrom
volodymyrlp:feat/update-user-endpoint

Conversation

@volodymyrlp

Copy link
Copy Markdown

What

Adds an update a user endpoint: PUT /users/:id.

  • db/store.js: new updateUser(id, { name, email }) helper — returns the updated user, or undefined for an unknown id.
  • routes/users.js: new PUT /users/:id route — parses the id, validates the body, calls the store helper, maps to 200 / 404.
  • NOTES.md: plan, model choice, commit split, and review write-up.

Why

The users resource could list, fetch, and create but not update. This fills the gap, following existing route conventions and going through db/store.js.

Behaviour

  • Valid name + email200 with the updated user
  • Unknown id → 404 { "error": "User not found" }
  • Missing field → 400 { "error": "name and email are required" } (validation runs before the store lookup)

What to test

  • Update an existing user, confirm both fields change (200)
  • PUT /users/9999 with a valid body → 404, no crash
  • PUT /users/1 with only name400
  • npm test (9 passing), npm run lint (clean)

volodymyrlp and others added 3 commits August 30, 2026 11:13
Returns the updated user, or undefined when the id is unknown, so the
route layer can distinguish a successful update from a missing user.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Validates name and email before the store lookup so a missing field
returns 400 even for an existing id; a lookup miss returns 404. Follows
the existing users route conventions and goes through db/store.js.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Covers the approved plan, model choice, commit split, and review.

Co-Authored-By: Claude Sonnet 5 <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