mirror of
https://github.com/usatiuk/ustk-todolist.git
synced 2025-10-28 23:57:49 +01:00
update
This commit is contained in:
@@ -29,11 +29,29 @@ router.post(
|
||||
}),
|
||||
);
|
||||
|
||||
// update
|
||||
router.patch(
|
||||
'/:todoId',
|
||||
asyncHelper(async (req, res) => {
|
||||
const { todoId } = req.params;
|
||||
const { text, completed } = req.body;
|
||||
const patch = {};
|
||||
if (text) {
|
||||
patch.text = text;
|
||||
}
|
||||
if (completed) {
|
||||
patch.completed = completed;
|
||||
}
|
||||
await Todo.update({ _id: todoId }, { $set: patch }).exec();
|
||||
res.json({ success: true });
|
||||
}),
|
||||
);
|
||||
|
||||
// delete
|
||||
router.delete(
|
||||
'/:todoId',
|
||||
asyncHelper(async (req, res) => {
|
||||
const { todoId } = req.params;
|
||||
console.log(todoId);
|
||||
await Todo.findByIdAndRemove(todoId).exec();
|
||||
res.json({ success: true });
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user