mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 00:08:49 +00:00
Updated menus to work better with list item linking
Lots of changes made (almost a refactor <--- four letter word to me... - Menu Items collection is now the "permanent" storage location for menu item for any day. So, if i set Green Chile Chicken Enchiladas, Beans, and Rice as an item for a day, it will be stored as a Menu Item for later use. - Linking menu items to items that can be added to a shopping list - This has been updated to be more reusable. So as you re-choose a menu item that's already got list items linked, it just shows up for you to use to build a shopping list as needed. - Deleting menu items from a menu - changed to delete them only from the menu, and not from the database. - Dashboard updated to pull today's menu item from the menu, and not the menu item list.
This commit is contained in:
parent
3f6618d906
commit
88fa7c1d22
13 changed files with 216 additions and 149 deletions
|
|
@ -117,4 +117,62 @@ Meteor.methods({
|
|||
Menus.remove({ _id: removeMenuIds[l] });
|
||||
}
|
||||
},
|
||||
});
|
||||
'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.');
|
||||
}
|
||||
|
||||
serveDateActual = new Date(dateSrv);
|
||||
|
||||
return Menus.update({ _id: menuId }, {
|
||||
$addToSet: {
|
||||
menuItems:
|
||||
{
|
||||
menuItemId: menuItemId,
|
||||
menuItemName: menuItem,
|
||||
serveDate: dateSrv,
|
||||
serveDateActual: serveDateActual,
|
||||
isLinked: isLinked
|
||||
},
|
||||
}
|
||||
});
|
||||
},
|
||||
'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 Menus.update({ 'menuItems.menuItemId': menuItemId }, {
|
||||
$set: {
|
||||
"menuItems.$.isLinked": isLinked
|
||||
}
|
||||
});
|
||||
},
|
||||
'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 Menus.update({ _id: ids[0] }, {
|
||||
$pull: {
|
||||
menuItems: {
|
||||
menuItemId: ids[1],
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,10 +12,8 @@ MenuItems.allow({
|
|||
});
|
||||
|
||||
Meteor.methods({
|
||||
'add.menuItem' (itemName, serveDate, menuId) {
|
||||
'add.menuItem' (itemName) {
|
||||
check(itemName, String);
|
||||
check(serveDate, String);
|
||||
check(menuId, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to add items. Make sure you are logged in with valid user credentials.');
|
||||
|
|
@ -25,11 +23,7 @@ Meteor.methods({
|
|||
|
||||
return MenuItems.insert({
|
||||
itemName: itemName,
|
||||
serveDate: serveDate,
|
||||
serveDateActual: serveDateActual,
|
||||
menuId: menuId,
|
||||
addedBy: this.userId,
|
||||
itemMade: false,
|
||||
dateAddedtoMenu: new Date(),
|
||||
isLinked: false,
|
||||
});
|
||||
|
|
@ -48,49 +42,6 @@ Meteor.methods({
|
|||
}
|
||||
});
|
||||
},
|
||||
'setMade.menuItem' (itemId) {
|
||||
check(itemId, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to set items as made. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
return MenuItems.update({ _id: itemId }, {
|
||||
$set: {
|
||||
itemMade: true,
|
||||
dateMade: new Date(),
|
||||
}
|
||||
});
|
||||
},
|
||||
'setAllMade.menuItem' (menuId) {
|
||||
check(menuId, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to set all items as made. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
return MenuItems.update({ menuId: menuId }, {
|
||||
$set: {
|
||||
itemMade: true,
|
||||
}
|
||||
}, {
|
||||
multi: true
|
||||
});
|
||||
},
|
||||
'setNotMade.menuItem' (itemId) {
|
||||
check(itemId, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to set items as not made. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
return MenuItems.update({ _id: itemId }, {
|
||||
$set: {
|
||||
itemMade: false,
|
||||
dateUnMade: new Date(),
|
||||
}
|
||||
});
|
||||
},
|
||||
'edit.madeItem' (itemId, itemName, serveDate) {
|
||||
check(itemId, String);
|
||||
check(itemName, String);
|
||||
|
|
@ -130,4 +81,4 @@ Meteor.methods({
|
|||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,32 +13,21 @@ MenuProdLinks.allow({
|
|||
});
|
||||
|
||||
Meteor.methods({
|
||||
'add.menuProdLinks' (menuItemId, prodNameArray) {
|
||||
'add.menuProdLinks' (menuItemId, menuItemName, prodNameArray) {
|
||||
check(menuItemId, String);
|
||||
check(prodNameArray, [String]);
|
||||
check(menuItemName, String);
|
||||
check(prodNameArray, [Object]);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to add menu and product links. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
};
|
||||
|
||||
let productObj = {};
|
||||
|
||||
let prodNameLength = prodNameArray.length;
|
||||
|
||||
for (i=0; i<prodNameLength; i++) {
|
||||
let product = Products.findOne({ prodName: prodNameArray[i] });
|
||||
if (typeof product != 'undefined' && product != null && product != "") {
|
||||
let prodId = product._id;
|
||||
MenuProdLinks.insert({
|
||||
menuItemId: menuItemId,
|
||||
prodName: prodNameArray[i],
|
||||
prodId: prodId,
|
||||
dateCreated: Date(),
|
||||
createdBy: this.userId
|
||||
});
|
||||
} else {
|
||||
console.log(" ERROR - unable to find a matching product by name: " + prodName[i] + ".");
|
||||
}
|
||||
}
|
||||
MenuProdLinks.insert({
|
||||
menuItemId: menuItemId,
|
||||
menuItemName: menuItemName,
|
||||
products: prodNameArray,
|
||||
dateCreated: Date(),
|
||||
createdBy: this.userId
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue