mirror of
https://github.com/usatiuk/ustk-todolist.git
synced 2025-10-28 23:57:49 +01:00
add removeWithTodos to TodoList model
This commit is contained in:
@@ -27,4 +27,11 @@ TodoListSchema.methods.slugify = function () {
|
|||||||
this.slug = slugify(this.name);
|
this.slug = slugify(this.name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TodoListSchema.methods.removeWithTodos = function () {
|
||||||
|
this.todos.forEach((todo) => {
|
||||||
|
todo.remove();
|
||||||
|
});
|
||||||
|
this.remove();
|
||||||
|
};
|
||||||
|
|
||||||
mongoose.model('TodoList', TodoListSchema);
|
mongoose.model('TodoList', TodoListSchema);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ router.post(
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// delete
|
||||||
router.delete(
|
router.delete(
|
||||||
'/:slug',
|
'/:slug',
|
||||||
asyncHelper(async (req, res) => {
|
asyncHelper(async (req, res) => {
|
||||||
@@ -41,10 +42,7 @@ router.delete(
|
|||||||
if (!list) {
|
if (!list) {
|
||||||
throw new NotFoundError();
|
throw new NotFoundError();
|
||||||
}
|
}
|
||||||
list.todos.forEach((todo) => {
|
await list.removeWithTodos();
|
||||||
todo.remove();
|
|
||||||
});
|
|
||||||
list.remove();
|
|
||||||
res.json({ success: true });
|
res.json({ success: true });
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user