Skip to content

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

Open
emcconde2 wants to merge 4 commits into
mate-academy:mainfrom
emcconde2:feature/update-user-endpoint
Open

Add PUT /users/:id (update a user)#122
emcconde2 wants to merge 4 commits into
mate-academy:mainfrom
emcconde2:feature/update-user-endpoint

Conversation

@emcconde2

Copy link
Copy Markdown

Summary

  • Add updateUser(id, { name, email }) to db/store.js, following the existing createUser/getUserById pattern.
  • Add PUT /users/:id to routes/users.js: validates name/email (400 if missing), returns 404 for an unknown id, 200 with the updated user otherwise.
  • Add NOTES.md documenting the plan, model choice, commit split, and self-review findings.

Why

Implements the "update a user" endpoint required by the course project, going through the existing db/store.js data-access pattern rather than touching data directly in the route.

Test plan

  • npm test is green (9/9), including the pre-written tests/update-user.test.js
  • PUT /users/:id with a valid body updates the user and returns 200
  • PUT /users/9999 (unknown id) returns 404
  • PUT /users/:id with a missing field returns 400
  • NOTES.md present with real content

Mirrors createUser/getUserById: finds a user by id and updates their
name/email in place, returning undefined if the id doesn't exist.
Validates name/email like POST does, then updates via the store
helper; returns 404 when the id doesn't exist.
Self-review flagged the duplicated find() lookup; updateUser now
calls the existing helper instead of re-implementing it.
Documents the plan, model choice, commit split, and what self-review
caught for the update-user endpoint.

@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 helper with proper user lookup via getUserById, undefined return for missing users, and in-place mutation. The routes/users.js endpoint properly handles PUT requests with id-parsing, input validation (400 for missing fields), 404 for unknown ids, and 200 responses with the updated user. The NOTES.md documents your plan, model choice, commit strategy, and self-review findings with appropriate specifics. All three files have been reviewed and meet the task requirements.


✨ 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