mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-26 15:58:50 +00:00
145 lines
4.5 KiB
JavaScript
145 lines
4.5 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { Mongo } from 'meteor/mongo';
|
|
import { check } from 'meteor/check';
|
|
import { MenuItems } from './menuItems';
|
|
import moment from 'moment';
|
|
import { mark } from '@babel/runtime/regenerator';
|
|
|
|
export const Menus = new Mongo.Collection('menus');
|
|
|
|
Menus.allow({
|
|
insert: function(userId, doc){
|
|
// if use id exists, allow insert
|
|
return !!userId;
|
|
},
|
|
});
|
|
|
|
Meteor.methods({
|
|
async '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 await Menus.insertAsync({
|
|
menuName: menuName,
|
|
menuOwner: this.userId,
|
|
menuComplete: false,
|
|
});
|
|
},
|
|
async '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 await Menus.updateAsync({ _id: menuId }, {
|
|
$set: {
|
|
menuName: menuName,
|
|
}
|
|
});
|
|
},
|
|
async '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 await Menus.removeAsync({ _id: menuId });
|
|
},
|
|
async '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 await Menus.updateAsync({ _id: menuId }, {
|
|
$set: {
|
|
menuComplete: true,
|
|
}
|
|
});
|
|
},
|
|
async '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 await Menus.updateAsync({ _id: menuId }, {
|
|
$set: {
|
|
menuComplete: false,
|
|
}
|
|
});
|
|
},
|
|
async 'clean.Menus' () {
|
|
if (!this.userId) {
|
|
throw new Meteor.Error('You are not allowed to clean up old Menus. Make sure you are logged in with valid user credentials.');
|
|
}
|
|
|
|
return await Menus.removeAsync({ menuComplete: true });
|
|
},
|
|
async 'addto.Menu' (menuId, menuItem, menuItemId, dateSrv, isLinked) {
|
|
check(menuId, String);
|
|
check(menuItem, String);
|
|
check(menuItemId, String);
|
|
check(dateSrv, String);
|
|
check(isLinked, Boolean);
|
|
|
|
if (!this.userId) {
|
|
throw new Meteor.Error('You are not allowed to add items to menus. Make sure you are logged in with valid user credentials.');
|
|
}
|
|
|
|
let serveDateActual = new Date(dateSrv);
|
|
|
|
return await Menus.updateAsync({ _id: menuId }, {
|
|
$addToSet: {
|
|
menuItems:
|
|
{
|
|
menuItemId: menuItemId,
|
|
menuItemName: menuItem,
|
|
serveDate: dateSrv,
|
|
serveDateActual: serveDateActual,
|
|
isLinked: isLinked
|
|
},
|
|
}
|
|
});
|
|
},
|
|
async 'link.inMenu' (menuItemId, isLinked) {
|
|
check(menuItemId, String);
|
|
check(isLinked, Boolean);
|
|
|
|
if (!this.userId) {
|
|
throw new Meteor.Error('You are not allowed to link menu items to products. Make sure you are logged in with valid user credentials.');
|
|
}
|
|
|
|
return await Menus.updateAsync({ 'menuItems.menuItemId': menuItemId }, {
|
|
$set: {
|
|
"menuItems.$.isLinked": isLinked
|
|
}
|
|
});
|
|
},
|
|
async 'delete.itemFromMenu' (itemIds) {
|
|
check(itemIds, String);
|
|
|
|
if (!this.userId) {
|
|
throw new Meteor.Error('You are not allowed to delete items from a menu. Make sure you are logged in with valid user credentials.');
|
|
}
|
|
|
|
let ids = itemIds.split('_');
|
|
// console.log("item ids: " + ids[0] + " and " + ids[1]);
|
|
|
|
return await Menus.updateAsync({ _id: ids[0] }, {
|
|
$pull: {
|
|
menuItems: {
|
|
menuItemId: ids[1],
|
|
},
|
|
}
|
|
});
|
|
}
|
|
});
|