mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 00:08:49 +00:00
57 lines
No EOL
1.7 KiB
JavaScript
57 lines
No EOL
1.7 KiB
JavaScript
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({
|
|
'add.category' (name) {
|
|
check(name, String);
|
|
|
|
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({
|
|
categoryName: name,
|
|
categroyOwner: this.userid,
|
|
});
|
|
},
|
|
'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.');
|
|
}
|
|
|
|
let categoryInfo = Categories.findOne({ _id: categoryId });
|
|
let myId = this.userId;
|
|
if (myId == categoryInfo.owner) {
|
|
return Categories.remove({ _id: categoryId });
|
|
} else {
|
|
console.log("User not allowed to delete this Category. Not the owner!");
|
|
return("Not Allowed!");
|
|
}
|
|
},
|
|
}); |