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
9 changes: 9 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# CLAUDE.md

## Architecture
- routes/users.js — the users resource, one route per action
- db/store.js — the in-memory data helper all routes go through
- tests/update-user.test.js — the tests



26 changes: 26 additions & 0 deletions NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# NOTES.md

## Plan
Plan the new endpoint "update a user" to

- update an existing user by id (PUT /users/:id)
- validate the input, rejecting missing or invalid fields with a clear error
- return a sensible "not found" response when the user doesn't exist, rather than crashing
- go through db/store.js for data access, following the existing pattern

The repo already contains the tests for this endpoint, in tests/update-user.test.js. They start red — making them pass is how


## Tasks

[ ] Add the updateUser function to db/store.js
[ ] Add the PUT /users/:id route to routes/users.js
[ ] Add input validation (return 400 for missing fields)
[ ] Add 404 handling for non-existent users

## Commits
First commit contains changes to db/store.js
Second commit contains the creation of the new endpoint (+ input validation, 400 and 404 return responses)

## Model
I will use opusplan
14 changes: 13 additions & 1 deletion db/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,16 @@ function createUser({ name, email }) {
return user;
}

module.exports = { getAllUsers, getUserById, createUser };
function updateUser(id, { name, email }) {
const user = getUserById(id);

if (!user) {
return undefined;
}

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 @@ -32,4 +32,22 @@ router.post("/", (req, res) => {
res.status(201).json(user);
});

// PUT /users/:id — update an existing user; name and email are required
router.put("/:id", (req, res) => {
const id = Number(req.params.id);
const { name, email } = req.body;

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

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

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

res.json(user);
});

module.exports = router;