Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Notes

## Plan

The plan was to add `updateUser(id, { name, email })` to `db/store.js` following the same pattern as `createUser`, then wire up a `PUT /users/:id` route in `routes/users.js` following the same shape as the existing GET and POST routes. The plan needed no edits — the test file made the requirements explicit (200 on success, 404 for unknown id, 400 for missing fields).

## Model choice

Claude Sonnet 4.6. The task is straightforward CRUD with clear tests, so the fastest capable model was the right call — no need for extended reasoning.

## Commit split

Two commits: one for the store helper (`updateUser`) and one for the route (`PUT /users/:id`). Each commit is independently understandable and the store change is useful even without the route.

## What the review caught

The review confirmed the implementation was correct: validation runs before the store lookup (so a 400 is returned before attempting an update), and `updateUser` returns `null` on a miss so the route can return 404 cleanly. No issues found.
10 changes: 9 additions & 1 deletion db/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ function createUser({ name, email }) {
return user;
}

module.exports = { getAllUsers, getUserById, createUser };
function updateUser(id, { name, email }) {
const user = users.find((u) => u.id === id);
if (!user) return null;
user.name = name;
user.email = email;
return user;
}

module.exports = { getAllUsers, getUserById, createUser, updateUser };
18 changes: 18 additions & 0 deletions routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ router.get("/:id", (req, res) => {
res.json(user);
});

// PUT /users/:id — update a user; name and email are required; 404 if not found
router.put("/:id", (req, res) => {
const { name, email } = req.body;

if (!name || !email) {
return res.status(400).json({ error: "name and email are required" });
}

const id = Number(req.params.id);
const user = store.updateUser(id, { name, email });

if (!user) {
return res.status(404).json({ error: "User not found" });
}

res.json(user);
});

// POST /users — create a user; name and email are required
router.post("/", (req, res) => {
const { name, email } = req.body;
Expand Down