This commit is contained in:
2018-05-19 19:51:04 +03:00
parent 8f0509b8f2
commit 97921d6ccc
4 changed files with 53 additions and 4 deletions

View File

@@ -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 });
}),