mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 08:18:50 +00:00
Adding Menu Support with methods.
This commit is contained in:
parent
29ddc544e5
commit
25ce44d9cf
1 changed files with 77 additions and 0 deletions
77
imports/api/menu.js
Normal file
77
imports/api/menu.js
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
import { Meteor } from 'meteor/meteor';
|
||||||
|
import { Mongo } from 'meteor/mongo';
|
||||||
|
import { check } from 'meteor/check';
|
||||||
|
|
||||||
|
export const Menus = new Mongo.Collection('menus');
|
||||||
|
|
||||||
|
Menus.allow({
|
||||||
|
insert: function(userId, doc){
|
||||||
|
// if use id exists, allow insert
|
||||||
|
return !!userId;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
Meteor.methods({
|
||||||
|
'add.menu' (menuName) {
|
||||||
|
check(menuName, String);
|
||||||
|
|
||||||
|
if (!this.userId) {
|
||||||
|
throw new Meteor.Error('You are not allowed to add menus. Make sure you are logged in with valid user credentials.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return Menus.insert({
|
||||||
|
menuName: menuName,
|
||||||
|
menuOwner: this.userId,
|
||||||
|
menuComplete: false,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
'edit.menu' (menuId, menuName) {
|
||||||
|
check(menuId, String);
|
||||||
|
check(menuName, String);
|
||||||
|
|
||||||
|
if (!this.userId) {
|
||||||
|
throw new Meteor.Error('You are not allowed to edit menus. Make sure you are logged in with valid user credentials.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return Menus.update({ _id: menuId }, {
|
||||||
|
$set: {
|
||||||
|
menuName: menuName,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
'delete.menu' (menuId) {
|
||||||
|
check(menuId, String);
|
||||||
|
|
||||||
|
if (!this.userId) {
|
||||||
|
throw new Meteor.Error('You are not allowed to delete menus. Make sure you are logged in with valid user credentials.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return Menus.remove({ _id: menuId });
|
||||||
|
},
|
||||||
|
'markMenu.complete' (menuId) {
|
||||||
|
check(menuId, String);
|
||||||
|
|
||||||
|
if (!this.userId) {
|
||||||
|
throw new Meteor.Error('You are not allowed to mark menus complete. Make sure you are logged in with valid user credentials.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return Menus.update({ _id: menuId }, {
|
||||||
|
$set: {
|
||||||
|
menuComplete: true,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
'markMenu.notComplete' (menuId) {
|
||||||
|
check(menuId, String);
|
||||||
|
|
||||||
|
if (!this.userId) {
|
||||||
|
throw new Meteor.Error('You are not allowed to mark menus not complete. Make sure you are logged in with valid user credentials.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return Menus.update({ _id: menuId }, {
|
||||||
|
$set: {
|
||||||
|
menuComplete: false,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue