Fix bug with updating linked menu items and products.

This commit is contained in:
Brian McGonagill 2024-08-16 12:33:27 -05:00
parent e10e234250
commit 457004df3f
2 changed files with 38 additions and 11 deletions

View file

@ -53,9 +53,6 @@ Template.addProdToListModal.events({
event.preventDefault();
let selectedItems = Session.get("itemsSelected");
let listId = $("#chooseList").val();
// console.log(" calling meteor method with items: ");
// console.dir(selectedItems);
// console.log(" and list id: "+ listId);
Meteor.call('add.itemsFromMenuItem', selectedItems, listId, function(err, result) {
if (err) {
console.log(" ERROR adding menu components to list: " + err);
@ -64,4 +61,4 @@ Template.addProdToListModal.events({
}
});
}
});
});

View file

@ -22,12 +22,42 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to add menu and product links. Make sure you are logged in with valid user credentials.');
};
MenuProdLinks.insert({
menuItemId: menuItemId,
menuItemName: menuItemName,
products: prodNameArray,
dateCreated: Date(),
createdBy: this.userId
let linkExists = MenuProdLinks.findOne({ menuItemId: menuItemId });
if (linkExists) {
console.log("sending to update method instead.");
Meteor.call('update.menuPordLInks', menuItemId, menuItemName, prodNameArray, function(err, result) {
if (err) {
console.log(" ERROR moving to the update method: " + err);
} else {
console.log("Successfully updated the menu prod links.")
}
});
} else {
return MenuProdLinks.insert({
menuItemId: menuItemId,
menuItemName: menuItemName,
products: prodNameArray,
dateCreated: Date(),
createdBy: this.userId
});
}
},
'update.menuPordLInks' (menuItemId, menuItemName, prodNameArray) {
check(menuItemId, 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.');
};
return MenuProdLinks.update({ menuItemId: menuItemId }, {
$set: {
products: prodNameArray,
dateUpdated: Date(),
updatedBy: this.userId
}
});
}
},
});