mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 00:08:49 +00:00
Fix bug with updating linked menu items and products.
This commit is contained in:
parent
e10e234250
commit
457004df3f
2 changed files with 38 additions and 11 deletions
|
|
@ -53,9 +53,6 @@ Template.addProdToListModal.events({
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
let selectedItems = Session.get("itemsSelected");
|
let selectedItems = Session.get("itemsSelected");
|
||||||
let listId = $("#chooseList").val();
|
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) {
|
Meteor.call('add.itemsFromMenuItem', selectedItems, listId, function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(" ERROR adding menu components to list: " + err);
|
console.log(" ERROR adding menu components to list: " + err);
|
||||||
|
|
|
||||||
|
|
@ -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.');
|
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({
|
let linkExists = MenuProdLinks.findOne({ menuItemId: menuItemId });
|
||||||
menuItemId: menuItemId,
|
|
||||||
menuItemName: menuItemName,
|
if (linkExists) {
|
||||||
products: prodNameArray,
|
console.log("sending to update method instead.");
|
||||||
dateCreated: Date(),
|
Meteor.call('update.menuPordLInks', menuItemId, menuItemName, prodNameArray, function(err, result) {
|
||||||
createdBy: this.userId
|
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
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue