Add PUT /users/:id endpoint - #97
Open
Fanca123 wants to merge 3 commits into
Open
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an "update a user" endpoint:
PUT /users/:id.name/emailare present (400 if not, matching the existingPOSThandler's check)db/store.js#updateUserhelperNOTES.mdwith the plan, model choice, commit rationale, and self-reviewWhy
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/POSThandlers already establish.What to test
PUT /users/:idwith a valid id and both fields → 200, updated user returnedPUT /users/:idfor a nonexistent id → 404 (not a crash)PUT /users/:idmissingnameoremail→ 400:id(e.g./users/abc) — falls through to 404 rather than erroring, sinceNumber("abc")isNaNand never matches a stored id.npm test(9/9) andnpm run lintboth pass locally.