mirror of
https://github.com/usatiuk/ustk-todolist.git
synced 2025-10-28 23:57:49 +01:00
refactoring
This commit is contained in:
@@ -9,6 +9,8 @@ const TodoList = mongoose.model('TodoList');
|
||||
|
||||
const asyncHelper = require('../asyncHelper');
|
||||
|
||||
const listIdMiddleware = require('./listIdMiddleware');
|
||||
|
||||
// index
|
||||
router.get(
|
||||
'/',
|
||||
@@ -34,16 +36,17 @@ router.post(
|
||||
// delete
|
||||
router.delete(
|
||||
'/:slug',
|
||||
listIdMiddleware,
|
||||
asyncHelper(async (req, res) => {
|
||||
const { slug } = req.params;
|
||||
const list = await TodoList.findOne({ slug })
|
||||
const { listId } = res.locals;
|
||||
const list = await TodoList.findById(listId)
|
||||
.populate('todos')
|
||||
.exec();
|
||||
if (!list) {
|
||||
throw new NotFoundError();
|
||||
}
|
||||
await list.removeWithTodos();
|
||||
await list.remove();
|
||||
res.json({ success: true });
|
||||
}),
|
||||
);
|
||||
|
||||
router.use('/:slug/todos', listIdMiddleware, require('./todos'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user