Skip to content

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

Open
MCapelati wants to merge 9 commits into
mate-academy:mainfrom
MCapelati:update-user
Open

Add PUT /users/:id (update a user) endpoint#145
MCapelati wants to merge 9 commits into
mate-academy:mainfrom
MCapelati:update-user

Conversation

@MCapelati

Copy link
Copy Markdown

What

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

  • db/store.js — new updateUser(id, { name, email }) helper; reuses getUserById,
    returns null for an unknown id, otherwise replaces name/email and returns the user.
  • routes/users.js — new PUT /:id handler that goes through the store:
    • 400 { error: "name and email are required" } when a field is missing
    • 400 { error: "email is not valid" } when the email is malformed
    • 404 { error: "User not found" } when the id doesn't exist (from our own check,
      not Express's unrouted-path fallthrough)
    • 200 with the updated user on success
  • NOTES.md — required write-up (plan, model choice, commit split, self-review).
  • CLAUDE.md — repo notes + the task checklist.
  • .gitignore — ignores a local README.pt-BR.md translation (not committed).

Why

tests/update-user.test.js shipped red. This implements the endpoint until the suite
is green, following the existing route patterns (POST /users validation style,
GET /users/:id 404 style) and routing all data access through db/store.js.

How it was built

One logical change per commit, running npm test between each so every commit turns
exactly one red test green: store helper → route (update + 404) → presence validation →
email-format validation (from self-review) → docs.

What a reviewer should test

npm test — full suite green (9/9). Manually:

  • PUT /users/<existing id> with a valid name + email200, body reflects the update
  • PUT /users/9999 (unknown id) → 404
  • PUT /users/1 with name only (no email) → 400
  • PUT /users/1 with email: "not-an-email"400

Notes / scope

  • PUT is a full replace: both name and email are required (not a partial PATCH).
  • POST /users keeps its presence-only check — retrofitting it was left out to keep
    this PR scoped to the new endpoint.
  • The store is in-memory and resets on restart (unchanged).

🤖 Generated with Claude Code

Marcelo Capellato Carvalho and others added 9 commits September 9, 2026 16:22
Add README.pt-BR.md to .gitignore; the translated README is a local
reading aid and does not need to be tracked in the repo.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
updateUser(id, { name, email }) resolves the record via getUserById,
returns null when the id is unknown, and otherwise overwrites name and
email in place before returning the updated user. Follows the null-signal
pattern the routes already rely on for not-found handling.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Wire a PUT handler on the users router that reads name and email from the
body, calls store.updateUser, and returns the updated user as JSON. When
updateUser reports no match it responds 404 with a "User not found"
error, matching the GET /users/:id behaviour.

Input validation is added in a follow-up commit.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Reject requests missing name or email with 400 and a "name and email are
required" error, before the store lookup runs. This keeps the validation
error ahead of the not-found check, so a malformed update to an existing
id fails as 400 rather than silently writing an undefined field.

Mirrors the existing POST /users validation.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Document the approved plan, the model choice (Sonnet 5) and the reasoning
that the plan covered every requirement before approval, as required by
the project brief and checked by tests/notes.test.js.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Capture the repo layout, the update-user task breakdown, and a running
checklist that is ticked off as each step and verification lands.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Mark Step 2 and the final verification complete now that npm test reports
9 passing / 0 failing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Self-review flagged that the endpoint only checked field presence, so
"grace@" or "not-an-email" would be written straight into the store. Add
an EMAIL_PATTERN test after the required-fields check: a bad email now
returns 400 with an "email is not valid" error.

Scoped to the new endpoint; POST /users keeps its presence-only check to
avoid an unrelated change in this PR.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Fix a stray character in the NOTES.md heading, add the commit-split and
"what the review caught" sections the brief asks for (including the
email-format finding and the decision to fix it on the new endpoint
only), and tick the matching self-review items in CLAUDE.md.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

@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

I am requesting changes because a critical file for the feature appears inconsistent across the submission: the PUT /users/:id route in routes/users.js could not be verified in all views, which is a blocker since the endpoint must exist and be wired to db/store.js. The data helper updateUser in db/store.js looks correct (returns null if not found and updates fields), but the HTTP layer must expose it. Please ensure routes/users.js includes a router.put('/:id', ...) handler that: validates name and email (400 on missing; also validate email format), calls store.updateUser(id, { name, email }), returns 404 when the user doesn’t exist, and returns the updated user with 200. Also confirm the file path is exactly routes/users.js and that it’s exported via module.exports = router. Once this is in place, run npm test and verify all tests pass. Nice work on the store layer and clear error messages; wiring up the route will complete the feature.


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

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

@MCapelati

Copy link
Copy Markdown
Author

All tests have passed, and route is implemented.

Please, read diff on https://github.com/mate-academy/claude-ship-a-change-end-to-end/pull/145/changes

@MCapelati

Copy link
Copy Markdown
Author

$ git diff main..update-user --stat
.gitignore | 3 +++
CLAUDE.md | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
NOTES.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++
db/store.js | 10 ++++++++-
routes/users.js | 26 ++++++++++++++++++++++
5 files changed, 161 insertions(+), 1 deletion(-)

diff.txt

@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.

Sorry, the pull request review was unsuccessful for the following reasons:

Warning

No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]

If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.

@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.

Sorry, the pull request review was unsuccessful for the following reasons:

Warning

No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]

If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.

@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.

Sorry, the pull request review was unsuccessful for the following reasons:

Warning

No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]

If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.

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