mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-24 13:39:35 +02:00
Pin/Delete category
This commit is contained in:
parent
bd5354a2e3
commit
0f2125e720
8 changed files with 156 additions and 7 deletions
|
@ -79,6 +79,24 @@ exports.updateCategory = asyncWrapper(async (req, res, next) => {
|
|||
// @route DELETE /api/categories/:id
|
||||
// @access Public
|
||||
exports.deleteCategory = asyncWrapper(async (req, res, next) => {
|
||||
const category = await Category.findOne({
|
||||
where: { id: req.params.id },
|
||||
include: [{
|
||||
model: Bookmark,
|
||||
as: 'bookmarks'
|
||||
}]
|
||||
});
|
||||
|
||||
if (!category) {
|
||||
return next(new ErrorResponse(`Category with id of ${req.params.id} was not found`, 404))
|
||||
}
|
||||
|
||||
category.bookmarks.forEach(async (bookmark) => {
|
||||
await Bookmark.destroy({
|
||||
where: { id: bookmark.id }
|
||||
})
|
||||
})
|
||||
|
||||
await Category.destroy({
|
||||
where: { id: req.params.id }
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue