Skip to content

Add PUT /users/:id endpoint - #97

Open
Fanca123 wants to merge 3 commits into
mate-academy:mainfrom
Fanca123:update-user-endpoint
Open

Add PUT /users/:id endpoint#97
Fanca123 wants to merge 3 commits into
mate-academy:mainfrom
Fanca123:update-user-endpoint

Conversation

@Fanca123

Copy link
Copy Markdown

What

Adds an "update a user" endpoint: PUT /users/:id.

  • Validates name/email are present (400 if not, matching the existing POST handler's check)
  • Updates the user via a new db/store.js#updateUser helper
  • Returns 404 for an unknown id instead of crashing
  • Adds NOTES.md with the plan, model choice, commit rationale, and self-review

Why

This is the "ship a change end to end" project task — bringing the users resource up to full CRUD (create/read/update) following the conventions the existing GET/POST handlers already establish.

What to test

  • PUT /users/:id with a valid id and both fields → 200, updated user returned
  • PUT /users/:id for a nonexistent id → 404 (not a crash)
  • PUT /users/:id missing name or email → 400
  • Also worth checking: a non-numeric :id (e.g. /users/abc) — falls through to 404 rather than erroring, since Number("abc") is NaN and never matches a stored id.

npm test (9/9) and npm run lint both pass locally.

Looks up the user by id and, if found, overwrites name/email in
place and returns it; returns null when the id doesn't exist so
callers can distinguish "updated" from "not found".
Validates that name and email are present (400 if not, matching the
POST handler's pattern), then updates via the store, returning 404
when the id doesn't exist instead of crashing. Turns the update-user
tests green.
Write-up of the plan, model choice, why the commits are split the
way they are, and what the pre-push review checked (and confirmed
was already fine).
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