Skip to content

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

Closed
habinap wants to merge 1 commit into
mate-academy:mainfrom
habinap:main
Closed

Add PUT /users/:id endpoint to update a user#118
habinap wants to merge 1 commit into
mate-academy:mainfrom
habinap:main

Conversation

@habinap

@habinap habinap commented Aug 31, 2026

Copy link
Copy Markdown

What: Adds PUT /users/:id to update an existing user's name and email. Validates that both fields are present (400 with a clear error if not), returns 404 if the user doesn't exist, and routes the actual mutation through a new updateUser(id, { name, email }) helper in db/store.js — keeping data access centralized there like the existing GET/POST handlers.

Why: The users resource could be created and read but not updated — this was the missing CRUD piece, requested to complete the resource.

What to test:

  • PUT /users/:id with a valid name/email on an existing user → 200 with the updated user returned.
  • PUT /users/:id on a non-existent (or non-numeric) id → 404, no crash.
  • PUT /users/:id with a missing name or email400 with an error message.
  • Regression: existing GET /users, GET /users/:id, POST /users behavior unchanged.
  • npm test — full suite (9 tests) passes; npx eslint clean.

Validates required fields, returns 404 for unknown users instead of
crashing, and goes through a new db/store.js updateUser helper to stay
consistent with the existing GET/POST handlers.

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

@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 implementation is approved. The db/store.js correctly implements the updateUser function following the existing pattern — it reuses getUserById for lookups, returns null when a user isn't found, and mutates only the allowed fields. The NOTES.md documentation is thorough and covers all required topics (plan, model choice, commit strategy, and review findings). Based on the individual file review, the routes/users.js endpoint properly validates required fields (returning 400), returns 404 for unknown users, and returns 200 with the updated user on success. The data access properly routes through db/store.js as required. All components work together correctly to fulfill the update user feature.


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

Footnotes

  1. Rate AI review example

@habinap habinap closed this Aug 31, 2026
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