Add list items from linked menu items

This commit is contained in:
Brian McGonagill 2024-07-29 16:58:08 -05:00
parent 91150f03b2
commit 00a99e0393
11 changed files with 203 additions and 5 deletions

View file

@ -54,9 +54,39 @@ Meteor.methods({
dateAddedToList: new Date(),
});
}
},
'add.itemsFromMenuItem' (itemIds, listId) {
check(itemIds, [String]);
check(listId, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add items from a menu. Make sure you are logged in with valid user credentials.');
}
console.dir(itemIds);
for (i=0; i < itemIds.length; i++) {
// let's check and make sure the product isn't already on the list
let onList = ListItems.find({ listId: listId, prodId: itemIds[i] }).count();
console.log("Number On List: " + onList);
if (onList == 0) {
// now pull the product
let prodInfo = Products.findOne({ _id: itemIds[i] });
ListItems.insert({
itemName: prodInfo.prodName,
listId: listId,
prodId: prodInfo._id,
addedBy: this.userId,
itemStore: prodInfo.prodStore,
itemOrdered: false,
itemReceived: false,
dateAddedToList: new Date(),
});
} else {
// product exists on list, move on to next
console.log("Product Exists on Selected List.");
}
}
},
'setOrdered.listItem' (itemId) {
check(itemId, String);