mirror of
https://github.com/usatiuk/ustk-todolist.git
synced 2025-10-29 08:07:48 +01:00
remove lists
This commit is contained in:
@@ -3,6 +3,8 @@ const mongoose = require('mongoose');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
const { NotFoundError } = require('../errors');
|
||||
|
||||
const TodoList = mongoose.model('TodoList');
|
||||
|
||||
const asyncHelper = require('../asyncHelper');
|
||||
@@ -29,4 +31,21 @@ router.post(
|
||||
}),
|
||||
);
|
||||
|
||||
router.delete(
|
||||
'/:id',
|
||||
asyncHelper(async (req, res) => {
|
||||
const { id } = req.params;
|
||||
const list = await TodoList.findById(id)
|
||||
.populate('todos')
|
||||
.exec();
|
||||
if (!list) {
|
||||
throw new NotFoundError();
|
||||
}
|
||||
list.todos.forEach((todo) => {
|
||||
todo.remove();
|
||||
});
|
||||
list.remove();
|
||||
res.json({ success: true });
|
||||
}),
|
||||
);
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user