Skip to content

Commit

Permalink
delete completed todos controller and route added
Browse files Browse the repository at this point in the history
  • Loading branch information
dinilgamage committed Feb 22, 2024
1 parent d1f3a23 commit ab3bcb4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions backend/controllers/todoController.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,14 @@ exports.deleteTodo = async (req, res) => {
} catch (err) {
res.status(500).json({ message: err.message });
}
};

exports.deleteCompletedTodos = async (req, res) => {
try {
await Todo.deleteMany({ completed: true });
const activeTodos = await Todo.find();
res.status(200).json(activeTodos);
} catch (err) {
res.status(500).json({ message: err.message });
}
};
1 change: 1 addition & 0 deletions backend/routes/todoRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ router.get('/:id', todoController.getTodo);
router.post('/', todoController.createTodo);
router.put('/:id', todoController.updateTodo);
router.delete('/:id', todoController.deleteTodo);
router.delete('/all/completed', todoController.deleteCompletedTodos);

module.exports = router;

0 comments on commit ab3bcb4

Please sign in to comment.