Skip to content

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

Closed
julien-vidal wants to merge 6 commits into
mate-academy:mainfrom
julien-vidal:feature/update-user-endpoint
Closed

Add PUT /users/:id endpoint to update a user#102
julien-vidal wants to merge 6 commits into
mate-academy:mainfrom
julien-vidal:feature/update-user-endpoint

Conversation

@julien-vidal

Copy link
Copy Markdown

Summary

  • Add an updateUser(id, { name, email }) helper in db/store.js, matching the shape of the existing getUserById/createUser helpers; returns undefined for an unknown id.
  • Add PUT /users/:id in routes/users.js: validates name (non-empty string) and email (basic shape, whitespace trimmed before both validation and storage) before the id lookup, then 404s if the user doesn't exist, or returns the updated user with 200.
  • Add tests/update-user.edge-cases.test.js covering cases the fixed grading file (tests/update-user.test.js, left untouched) doesn't: non-numeric id, malformed/whitespace-padded email, empty body, whitespace-only name, non-string fields, that the update actually persists to the store, and that the id is never reassigned.
  • Add NOTES.md with the plan, model choice, commit rationale, and self-review notes (including a bug caught during review: email validation ran a regex against the untrimmed value while storage trimmed it, so a valid email with incidental surrounding whitespace was wrongly rejected — fixed by trimming before validating).

Test plan

  • npm test — 18/18 passing, including all three tests in tests/update-user.test.js
  • npm run lint — clean
  • Reviewer: confirm PUT /users/1 with a valid body returns 200 and the updated fields
  • Reviewer: confirm PUT /users/9999 returns 404
  • Reviewer: confirm PUT /users/1 with a missing/invalid field returns 400

🤖 Generated with Claude Code

julien-vidal added 6 commits August 24, 2026 15:01
Mirrors getUserById/createUser's shape so routes stay thin. Returns
undefined for an unknown id, matching getUserById's contract.
…ling

Validates name (non-empty string) and email (basic shape) before the
lookup, so a bad body is rejected the same way whether or not the id
exists. Turns tests/update-user.test.js green.
Adds cases the fixed grading file doesn't check: non-numeric id,
malformed email, empty body, whitespace-only name, non-string fields,
and that the update actually persists to the store (not just the
response) without reassigning the user's id.
Covers the approved plan and the edit made to it, model choice, commit
split, and what self-review caught.
isValidEmail regex-tested the raw value while the store write trimmed
it, so a valid email with incidental surrounding whitespace was
rejected with 400 instead of being accepted and stored trimmed.
@julien-vidal julien-vidal closed this by deleting the head repository Sep 3, 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.

1 participant