Skip to content

Commit 7ca8092

Browse files
NathanaelBetaclaude
andcommitted
Add PUT /users/:id endpoint to update a user's name and email
Returns 400 when either field is missing, 404 when the id does not exist, and 200 with the updated user object on success. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 03c42d9 commit 7ca8092

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

routes/users.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,22 @@ router.post("/", (req, res) => {
3232
res.status(201).json(user);
3333
});
3434

35+
// PUT /users/:id — update name and email; 400 if fields missing, 404 if not found
36+
router.put("/:id", (req, res) => {
37+
const { name, email } = req.body;
38+
39+
if (!name || !email) {
40+
return res.status(400).json({ error: "name and email are required" });
41+
}
42+
43+
const id = Number(req.params.id);
44+
const user = store.updateUser(id, { name, email });
45+
46+
if (!user) {
47+
return res.status(404).json({ error: "User not found" });
48+
}
49+
50+
res.json(user);
51+
});
52+
3553
module.exports = router;

0 commit comments

Comments
 (0)