diff --git a/backend/controllers/todoController.js b/backend/controllers/todoController.js index 675d81f..3e9a556 100644 --- a/backend/controllers/todoController.js +++ b/backend/controllers/todoController.js @@ -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 }); + } }; \ No newline at end of file diff --git a/backend/routes/todoRoutes.js b/backend/routes/todoRoutes.js index 4a440e8..74d31f5 100644 --- a/backend/routes/todoRoutes.js +++ b/backend/routes/todoRoutes.js @@ -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; \ No newline at end of file