From ab3bcb49bbf4607b388b1ac3479989015f513448 Mon Sep 17 00:00:00 2001 From: Dinil Date: Thu, 22 Feb 2024 20:29:32 +0530 Subject: [PATCH] delete completed todos controller and route added --- backend/controllers/todoController.js | 10 ++++++++++ backend/routes/todoRoutes.js | 1 + 2 files changed, 11 insertions(+) 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