Add PUT /users/:id (update a user) endpoint - #145
Conversation
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
left a comment
There was a problem hiding this comment.
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
|
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 |
|
$ git diff main..update-user --stat |
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
What
Adds an update a user endpoint to the users resource:
PUT /users/:id.db/store.js— newupdateUser(id, { name, email })helper; reusesgetUserById,returns
nullfor an unknown id, otherwise replacesname/emailand returns the user.routes/users.js— newPUT /:idhandler that goes through the store:400 { error: "name and email are required" }when a field is missing400 { error: "email is not valid" }when the email is malformed404 { error: "User not found" }when the id doesn't exist (from our own check,not Express's unrouted-path fallthrough)
200with the updated user on successNOTES.md— required write-up (plan, model choice, commit split, self-review).CLAUDE.md— repo notes + the task checklist..gitignore— ignores a localREADME.pt-BR.mdtranslation (not committed).Why
tests/update-user.test.jsshipped red. This implements the endpoint until the suiteis green, following the existing route patterns (
POST /usersvalidation style,GET /users/:id404 style) and routing all data access throughdb/store.js.How it was built
One logical change per commit, running
npm testbetween each so every commit turnsexactly 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 validname+email→200, body reflects the updatePUT /users/9999(unknown id) →404PUT /users/1withnameonly (noemail) →400PUT /users/1withemail: "not-an-email"→400Notes / scope
PUTis a full replace: bothnameandemailare required (not a partial PATCH).POST /userskeeps its presence-only check — retrofitting it was left out to keepthis PR scoped to the new endpoint.
🤖 Generated with Claude Code