mirror of
https://github.com/vale981/Vulcan
synced 2025-03-09 12:16:37 -04:00
25 lines
No EOL
710 B
JavaScript
25 lines
No EOL
710 B
JavaScript
Meteor.methods({
|
|
removeCategory: function (categoryId) {
|
|
|
|
check(categoryId, String);
|
|
|
|
if (Users.is.admin(this.userId)) {
|
|
|
|
var category = Categories.findOne(categoryId);
|
|
|
|
// delete category
|
|
Categories.remove(categoryId);
|
|
|
|
// find any direct children of this category and make them root categories
|
|
Categories.find({parentId: categoryId}).forEach(function (category) {
|
|
Categories.update(category._id, {$unset: {parentId: ""}});
|
|
});
|
|
|
|
// find any post with this category and remove it
|
|
var postsUpdated = Posts.update({categories: {$in: [categoryId]}}, {$pull: {categories: categoryId}}, {multi: true});
|
|
|
|
return postsUpdated;
|
|
|
|
}
|
|
}
|
|
}); |