2022-08-05 16:55:56 -05:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
|
import { Mongo } from 'meteor/mongo';
|
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
|
|
|
|
|
|
export const Categories = new Mongo.Collection('categories');
|
|
|
|
|
|
|
|
|
|
Categories.allow({
|
|
|
|
|
insert: function(userId, doc){
|
|
|
|
|
// if use id exists, allow insert
|
|
|
|
|
return !!userId;
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Meteor.methods({
|
2022-08-15 18:07:39 -05:00
|
|
|
'add.category' (categoryName) {
|
|
|
|
|
check(categoryName, String);
|
2022-08-05 16:55:56 -05:00
|
|
|
|
|
|
|
|
if (!this.userId) {
|
|
|
|
|
throw new Meteor.Error('You are not allowed to add categories. Make sure you are logged in with valid user credentials.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Categories.insert({
|
2022-08-15 18:07:39 -05:00
|
|
|
categoryName: categoryName,
|
|
|
|
|
categoryOwner: this.userId,
|
2022-08-05 16:55:56 -05:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
'edit.category' (categoryId, categoryName,) {
|
|
|
|
|
check(categoryId, String);
|
|
|
|
|
check(categoryName, String);
|
|
|
|
|
|
|
|
|
|
if (!this.userId) {
|
|
|
|
|
throw new Meteor.Error('You are not allowed to edit categories. Make sure you are logged in with valid user credentials.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Categories.update({ _id: categoryId }, {
|
|
|
|
|
$set: {
|
|
|
|
|
categoryName: categoryName,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
'delete.category' (categoryId) {
|
|
|
|
|
check(categoryId, String);
|
|
|
|
|
|
|
|
|
|
if (!this.userId) {
|
|
|
|
|
throw new Meteor.Error('You are not allowed to delete categories. Make sure you are logged in with valid user credentials.');
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 11:18:18 -05:00
|
|
|
return Categories.remove({ _id: categoryId });
|
2022-08-05 16:55:56 -05:00
|
|
|
},
|
|
|
|
|
});
|