Updates for async and await - still

This commit is contained in:
Brian McGonagill 2025-07-22 13:50:49 -05:00
parent febb36d75f
commit 706c5dc3ef
18 changed files with 220 additions and 233 deletions

View file

@ -71,9 +71,8 @@ Template.listMgmtForm.events({
const addList = async(listName, shared) => { const addList = async(listName, shared) => {
let result = await Meteor.callAsync('add.list', listName, shared); let result = await Meteor.callAsync('add.list', listName, shared);
if (!result) { if (!result) {
// console.log(" ERROR adding list name: "); console.log("Nothing returned from method call add.list");
} else { } else {
// console.log(" SUCCESS adding list name.");
$("#listNameInp").val(""); $("#listNameInp").val("");
$("#isShared").prop("checked", false); $("#isShared").prop("checked", false);
} }
@ -82,9 +81,8 @@ const addList = async(listName, shared) => {
const editList = async(listId, listName, shared) => { const editList = async(listId, listName, shared) => {
let result = await Meteor.callAsync('edit.list', listId, listName, shared); let result = await Meteor.callAsync('edit.list', listId, listName, shared);
if (!result) { if (!result) {
// console.log(" ERROR editing list name: " + err); // console.log("Nothing returned from method call edit.list");
} else { } else {
// console.log(" SUCCESS editing list name.");
$("#listNameInp").val(""); $("#listNameInp").val("");
$("#isShared").prop("checked", false); $("#isShared").prop("checked", false);
Session.set("listNameEditMode", false); Session.set("listNameEditMode", false);

View file

@ -14,7 +14,7 @@ ListItems.allow({
}); });
Meteor.methods({ Meteor.methods({
'add.listItem' (itemName, listId) { async 'add.listItem' (itemName, listId) {
check(itemName, String); check(itemName, String);
check(listId, String); check(listId, String);
@ -25,19 +25,18 @@ Meteor.methods({
let iname = itemName.charAt(0).toUpperCase() + itemName.slice(1); let iname = itemName.charAt(0).toUpperCase() + itemName.slice(1);
// look up the item from the Products collection // look up the item from the Products collection
const prodIsIn = async() => {
let prodInfo = await Products.findOneAsync({ prodName: iname }); let prodInfo = await Products.findOneAsync({ prodName: iname });
try { try {
if (!prodInfo) { if (!prodInfo) {
// add product info first // add product info first
const addProd = async() => {
let added = await Meteor.callAsync("add.product", itemName, [""]); let added = await Meteor.callAsync("add.product", itemName, [""]);
if (!added) { if (!added) {
console.log(" ERROR adding item to products: " + err); console.log(" ERROR adding item to products: " + err);
} else { } else {
// console.log(" SUCCESS adding item to Products."); // console.log(" SUCCESS adding item to Products.");
return ListItems.insertAsync({ return await ListItems.insertAsync({
itemName: iname, itemName: iname,
listId: listId, listId: listId,
prodId: result, prodId: result,
@ -48,9 +47,8 @@ Meteor.methods({
dateAddedToList: new Date(), dateAddedToList: new Date(),
}); });
} }
}
} else { } else {
return ListItems.insertAsync({ return await ListItems.insertAsync({
itemName: iname, itemName: iname,
listId: listId, listId: listId,
prodId: prodInfo._id, prodId: prodInfo._id,
@ -64,11 +62,8 @@ Meteor.methods({
} catch(error) { } catch(error) {
console.log(" ERROR adding new product and item: " + error); console.log(" ERROR adding new product and item: " + error);
} }
}
let prodIn = prodIsIn();
return prodIn;
}, },
'add.itemsFromMenuItem' (itemIds, listId) { async 'add.itemsFromMenuItem' (itemIds, listId) {
check(itemIds, [String]); check(itemIds, [String]);
check(listId, String); check(listId, String);
@ -80,11 +75,14 @@ Meteor.methods({
for (i=0; i < itemIds.length; i++) { for (i=0; i < itemIds.length; i++) {
// let's check and make sure the product isn't already on the list // let's check and make sure the product isn't already on the list
let onList = ListItems.find({ listId: listId, prodId: itemIds[i] }).count(); let onList = await ListItems.find({ listId: listId, prodId: itemIds[i] }).count();
console.log("Number On List: " + onList); // console.log("Number On List: " + onList);
if (onList == 0) { if (onList == 0) {
// now pull the product // now pull the product
let prodInfo = Products.findOne({ _id: itemIds[i] }); let prodInfo = await Products.findOneAsync({ _id: itemIds[i] });
if (!prodInfo) {
console.log("Unable to load product info.");
} else {
ListItems.insertAsync({ ListItems.insertAsync({
itemName: prodInfo.prodName, itemName: prodInfo.prodName,
listId: listId, listId: listId,
@ -95,52 +93,53 @@ Meteor.methods({
itemReceived: false, itemReceived: false,
dateAddedToList: new Date(), dateAddedToList: new Date(),
}); });
}
} else { } else {
// product exists on list, move on to next // product exists on list, move on to next
console.log("Product Exists on Selected List."); console.log("Product Exists on Selected List.");
} }
} }
}, },
'setOrdered.listItem' (itemId) { async 'setOrdered.listItem' (itemId) {
check(itemId, String); check(itemId, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to set items as ordered. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to set items as ordered. Make sure you are logged in with valid user credentials.');
} }
return ListItems.updateAsync({ _id: itemId }, { return await ListItems.updateAsync({ _id: itemId }, {
$set: { $set: {
itemOrdered: true, itemOrdered: true,
dateOrdered: new Date(), dateOrdered: new Date(),
} }
}); });
}, },
'setAllOrdered.listItem' (shopListId) { async 'setAllOrdered.listItem' (shopListId) {
// set all items that are not already set as ordered, or set as received to ordered on this list // set all items that are not already set as ordered, or set as received to ordered on this list
}, },
'setNotOrdered.listItem' (itemId) { async 'setNotOrdered.listItem' (itemId) {
check(itemId, String); check(itemId, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to set items as not ordered. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to set items as not ordered. Make sure you are logged in with valid user credentials.');
} }
return ListItems.updateAsync({ _id: itemId }, { return await ListItems.updateAsync({ _id: itemId }, {
$set: { $set: {
itemOrdered: false, itemOrdered: false,
dateUnOrdered: new Date(), dateUnOrdered: new Date(),
} }
}); });
}, },
'setReceived.listItem' (itemId) { async 'setReceived.listItem' (itemId) {
check(itemId, String); check(itemId, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to set items as received. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to set items as received. Make sure you are logged in with valid user credentials.');
} }
return ListItems.updateAsync({ _id: itemId }, { return await ListItems.updateAsync({ _id: itemId }, {
$set: { $set: {
itemReceived: true, itemReceived: true,
dateReceived: new Date(), dateReceived: new Date(),
@ -148,25 +147,25 @@ Meteor.methods({
}); });
}, },
'setNotReceived.listItem' (shopListId) { async 'setNotReceived.listItem' (shopListId) {
check(itemId, String); check(itemId, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to set items as not received. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to set items as not received. Make sure you are logged in with valid user credentials.');
} }
return ListItems.updateAsync({ _id: itemId }, { return await ListItems.updateAsync({ _id: itemId }, {
$set: { $set: {
itemReceived: false, itemReceived: false,
dateNotReceived: new Date(), dateNotReceived: new Date(),
} }
}); });
}, },
'setAllReceived.listItem' () { async 'setAllReceived.listItem' () {
// set all items that are not already listed as received to received on this list // set all items that are not already listed as received to received on this list
}, },
'edit.listItem' (itemId, itemName) { async 'edit.listItem' (itemId, itemName) {
check(itemId, String); check(itemId, String);
check(itemName, String); check(itemName, String);
@ -174,19 +173,19 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to add items. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to add items. Make sure you are logged in with valid user credentials.');
} }
return ListItems.updateAsync({ _id: itemId }, { return await ListItems.updateAsync({ _id: itemId }, {
$set: { $set: {
itemName: itemName, itemName: itemName,
} }
}); });
}, },
'delete.listItem' (itemId) { async 'delete.listItem' (itemId) {
check(itemId, String); check(itemId, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete list items. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to delete list items. Make sure you are logged in with valid user credentials.');
} }
return ListItems.removeAsync({ _id: itemId }); return await ListItems.removeAsync({ _id: itemId });
} }
}); });

View file

@ -12,7 +12,7 @@ Lists.allow({
}); });
Meteor.methods({ Meteor.methods({
'add.list' (listName, isShared) { async 'add.list' (listName, isShared) {
check(listName, String); check(listName, String);
check(isShared, Boolean); check(isShared, Boolean);
@ -20,14 +20,14 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to add lists. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to add lists. Make sure you are logged in with valid user credentials.');
} }
return Lists.insertAsync({ return await Lists.insertAsync({
listName: listName, listName: listName,
listShared: isShared, listShared: isShared,
listOwner: this.userId, listOwner: this.userId,
listComplete: false, listComplete: false,
}); });
}, },
'edit.list' (listId, listName, isShared) { async 'edit.list' (listId, listName, isShared) {
check(listId, String); check(listId, String);
check(listName, String); check(listName, String);
check(isShared, Boolean); check(isShared, Boolean);
@ -36,55 +36,55 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to edit lists. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to edit lists. Make sure you are logged in with valid user credentials.');
} }
return Lists.updateAsync({ _id: listId }, { return await Lists.updateAsync({ _id: listId }, {
$set: { $set: {
listName: listName, listName: listName,
listShared: isShared, listShared: isShared,
} }
}); });
}, },
'delete.list' (listId) { async 'delete.list' (listId) {
check(listId, String); check(listId, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete lists. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to delete lists. Make sure you are logged in with valid user credentials.');
} }
return Lists.removeAsync({ _id: listId }); return await Lists.removeAsync({ _id: listId });
}, },
'mark.complete' (listId) { async 'mark.complete' (listId) {
check(listId, String); check(listId, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to mark lists complete. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to mark lists complete. Make sure you are logged in with valid user credentials.');
} }
return Lists.updateAsync({ _id: listId }, { return await Lists.updateAsync({ _id: listId }, {
$set: { $set: {
listComplete: true, listComplete: true,
completedOn: new Date() completedOn: new Date()
} }
}); });
}, },
'mark.incomplete' (listId) { async 'mark.incomplete' (listId) {
check(listId, String); check(listId, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to restore completed lists. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to restore completed lists. Make sure you are logged in with valid user credentials.');
} }
return Lists.updateAsync({ _id: listId }, { return await Lists.updateAsync({ _id: listId }, {
$set: { $set: {
listComplete: false, listComplete: false,
completedOn: new Date() completedOn: new Date()
} }
}); });
}, },
'clean.Lists' () { async 'clean.Lists' () {
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to clean up old lists. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to clean up old lists. Make sure you are logged in with valid user credentials.');
} }
return Lists.removeAsync({ listComplete: true }); return await Lists.removeAsync({ listComplete: true });
}, },
}); });

View file

@ -12,10 +12,10 @@ MScripts.allow({
}); });
Meteor.methods({ Meteor.methods({
'set.ScriptRun' (scriptName) { async 'set.ScriptRun' (scriptName) {
check(scriptName, String); check(scriptName, String);
MScripts.insertAsync({ return await MScripts.insertAsync({
scriptName: scriptName, scriptName: scriptName,
hasRun: true, hasRun: true,
runOn: new Date(), runOn: new Date(),

View file

@ -15,20 +15,20 @@ Menus.allow({
}); });
Meteor.methods({ Meteor.methods({
'add.menu' (menuName) { async 'add.menu' (menuName) {
check(menuName, String); check(menuName, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to add menus. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to add menus. Make sure you are logged in with valid user credentials.');
} }
return Menus.insertAsync({ return await Menus.insertAsync({
menuName: menuName, menuName: menuName,
menuOwner: this.userId, menuOwner: this.userId,
menuComplete: false, menuComplete: false,
}); });
}, },
'edit.menu' (menuId, menuName) { async 'edit.menu' (menuId, menuName) {
check(menuId, String); check(menuId, String);
check(menuName, String); check(menuName, String);
@ -36,48 +36,48 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to edit menus. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to edit menus. Make sure you are logged in with valid user credentials.');
} }
return Menus.updateAsync({ _id: menuId }, { return await Menus.updateAsync({ _id: menuId }, {
$set: { $set: {
menuName: menuName, menuName: menuName,
} }
}); });
}, },
'delete.menu' (menuId) { async 'delete.menu' (menuId) {
check(menuId, String); check(menuId, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete menus. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to delete menus. Make sure you are logged in with valid user credentials.');
} }
return Menus.removeAsync({ _id: menuId }); return await Menus.removeAsync({ _id: menuId });
}, },
'markMenu.complete' (menuId) { async 'markMenu.complete' (menuId) {
check(menuId, String); check(menuId, String);
if (!this.userId) { 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.'); throw new Meteor.Error('You are not allowed to mark menus complete. Make sure you are logged in with valid user credentials.');
} }
return Menus.updateAsync({ _id: menuId }, { return await Menus.updateAsync({ _id: menuId }, {
$set: { $set: {
menuComplete: true, menuComplete: true,
} }
}); });
}, },
'markMenu.notComplete' (menuId) { async 'markMenu.notComplete' (menuId) {
check(menuId, String); check(menuId, String);
if (!this.userId) { 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.'); throw new Meteor.Error('You are not allowed to mark menus not complete. Make sure you are logged in with valid user credentials.');
} }
return Menus.updateAsync({ _id: menuId }, { return await Menus.updateAsync({ _id: menuId }, {
$set: { $set: {
menuComplete: false, menuComplete: false,
} }
}); });
}, },
'clean.Menus' () { async 'clean.Menus' () {
if (!this.userId) { 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.'); throw new Meteor.Error('You are not allowed to clean up old Menus. Make sure you are logged in with valid user credentials.');
} }
@ -114,10 +114,10 @@ Meteor.methods({
// finally we'll cycle through the ids and remove the items we collected up. // finally we'll cycle through the ids and remove the items we collected up.
for (let l = 0; l < removeMenuIds.length; l++) { for (let l = 0; l < removeMenuIds.length; l++) {
Menus.removeAsync({ _id: removeMenuIds[l] }); await Menus.removeAsync({ _id: removeMenuIds[l] });
} }
}, },
'addto.Menu' (menuId, menuItem, menuItemId, dateSrv, isLinked) { async 'addto.Menu' (menuId, menuItem, menuItemId, dateSrv, isLinked) {
check(menuId, String); check(menuId, String);
check(menuItem, String); check(menuItem, String);
check(menuItemId, String); check(menuItemId, String);
@ -130,7 +130,7 @@ Meteor.methods({
let serveDateActual = new Date(dateSrv); let serveDateActual = new Date(dateSrv);
return Menus.updateAsync({ _id: menuId }, { return await Menus.updateAsync({ _id: menuId }, {
$addToSet: { $addToSet: {
menuItems: menuItems:
{ {
@ -143,7 +143,7 @@ Meteor.methods({
} }
}); });
}, },
'link.inMenu' (menuItemId, isLinked) { async 'link.inMenu' (menuItemId, isLinked) {
check(menuItemId, String); check(menuItemId, String);
check(isLinked, Boolean); check(isLinked, Boolean);
@ -151,13 +151,13 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to link menu items to products. Make sure you are logged in with valid user credentials.'); 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.updateAsync({ 'menuItems.menuItemId': menuItemId }, { return await Menus.updateAsync({ 'menuItems.menuItemId': menuItemId }, {
$set: { $set: {
"menuItems.$.isLinked": isLinked "menuItems.$.isLinked": isLinked
} }
}); });
}, },
'delete.itemFromMenu' (itemIds) { async 'delete.itemFromMenu' (itemIds) {
check(itemIds, String); check(itemIds, String);
if (!this.userId) { if (!this.userId) {
@ -167,7 +167,7 @@ Meteor.methods({
let ids = itemIds.split('_'); let ids = itemIds.split('_');
console.log("item ids: " + ids[0] + " and " + ids[1]); console.log("item ids: " + ids[0] + " and " + ids[1]);
return Menus.updateAsync({ _id: ids[0] }, { return await Menus.updateAsync({ _id: ids[0] }, {
$pull: { $pull: {
menuItems: { menuItems: {
menuItemId: ids[1], menuItemId: ids[1],

View file

@ -12,21 +12,21 @@ MenuItems.allow({
}); });
Meteor.methods({ Meteor.methods({
'add.menuItem' (itemName) { async 'add.menuItem' (itemName) {
check(itemName, String); check(itemName, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to add items. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to add items. Make sure you are logged in with valid user credentials.');
} }
return MenuItems.insertAsync({ return await MenuItems.insertAsync({
itemName: itemName, itemName: itemName,
addedBy: this.userId, addedBy: this.userId,
dateAddedtoMenu: new Date(), dateAddedtoMenu: new Date(),
isLinked: false, isLinked: false,
}); });
}, },
'update.menuItemLinked' (itemId, isLinked) { async 'update.menuItemLinked' (itemId, isLinked) {
check(itemId, String); check(itemId, String);
check(isLinked, Boolean); check(isLinked, Boolean);
@ -34,13 +34,13 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to set this menu item as linked to products. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to set this menu item as linked to products. Make sure you are logged in with valid user credentials.');
} }
return MenuItems.updateAsync({ _id: itemId }, { return await MenuItems.updateAsync({ _id: itemId }, {
$set: { $set: {
isLinked: isLinked, isLinked: isLinked,
} }
}); });
}, },
'edit.madeItem' (itemId, itemName) { async 'edit.madeItem' (itemId, itemName) {
check(itemId, String); check(itemId, String);
check(itemName, String); check(itemName, String);
@ -48,22 +48,22 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to edit menu items. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to edit menu items. Make sure you are logged in with valid user credentials.');
} }
return MenuItems.updateAsync({ _id: itemId }, { return await MenuItems.updateAsync({ _id: itemId }, {
$set: { $set: {
itemName: itemName, itemName: itemName,
} }
}); });
}, },
'delete.menuItem' (itemId) { async 'delete.menuItem' (itemId) {
check(itemId, String); check(itemId, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete menu items. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to delete menu items. Make sure you are logged in with valid user credentials.');
} }
return MenuItems.removeAsync({ _id: itemId }); return await MenuItems.removeAsync({ _id: itemId });
}, },
'shiftDate' (itemId, momentAddDay) { async 'shiftDate' (itemId, momentAddDay) {
check(itemId, String); check(itemId, String);
check(momentAddDay, String); check(momentAddDay, String);
@ -71,7 +71,7 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to shift menu item dates. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to shift menu item dates. Make sure you are logged in with valid user credentials.');
} }
return MenuItems.updateAsync({ _id: itemId }, { return await MenuItems.updateAsync({ _id: itemId }, {
$set: { $set: {
serveDate: momentAddDay, serveDate: momentAddDay,
} }

View file

@ -13,7 +13,7 @@ MenuProdLinks.allow({
}); });
Meteor.methods({ Meteor.methods({
'add.menuProdLinks' (menuItemId, menuItemName, prodNameArray) { async 'add.menuProdLinks' (menuItemId, menuItemName, prodNameArray) {
check(menuItemId, String); check(menuItemId, String);
check(menuItemName, String); check(menuItemName, String);
check(prodNameArray, [Object]); check(prodNameArray, [Object]);
@ -34,7 +34,7 @@ Meteor.methods({
} }
}); });
} else { } else {
return MenuProdLinks.insertAsync({ return await MenuProdLinks.insertAsync({
menuItemId: menuItemId, menuItemId: menuItemId,
menuItemName: menuItemName, menuItemName: menuItemName,
products: prodNameArray, products: prodNameArray,
@ -43,7 +43,7 @@ Meteor.methods({
}); });
} }
}, },
'update.menuPordLInks' (menuItemId, menuItemName, prodNameArray) { async 'update.menuPordLInks' (menuItemId, menuItemName, prodNameArray) {
check(menuItemId, String); check(menuItemId, String);
check(menuItemName, String); check(menuItemName, String);
check(prodNameArray, [Object]); check(prodNameArray, [Object]);
@ -52,7 +52,7 @@ 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.');
}; };
return MenuProdLinks.updateAsync({ menuItemId: menuItemId }, { return await MenuProdLinks.updateAsync({ menuItemId: menuItemId }, {
$set: { $set: {
products: prodNameArray, products: prodNameArray,
dateUpdated: Date(), dateUpdated: Date(),

View file

@ -12,7 +12,7 @@ Products.allow({
}); });
Meteor.methods({ Meteor.methods({
'add.product' (prodName, prodStore) { async 'add.product' (prodName, prodStore) {
check(prodName, String); check(prodName, String);
check(prodStore, [String]); check(prodStore, [String]);
@ -24,11 +24,10 @@ Meteor.methods({
// first does this product already exist? // first does this product already exist?
const productIsIn = async() => {
let prodExists = await Products.findOneAsync({ prodName: pname }); let prodExists = await Products.findOneAsync({ prodName: pname });
try { try {
if (!prodExists) { if (!prodExists) {
return Products.insertAsync({ return await Products.insertAsync({
prodName: pname, prodName: pname,
prodOwner: this.userId, prodOwner: this.userId,
prodStore: prodStore, prodStore: prodStore,
@ -37,11 +36,8 @@ Meteor.methods({
} catch(error) { } catch(error) {
console.log(" ERROR adding Pdocut: " + error); console.log(" ERROR adding Pdocut: " + error);
} }
}
let prodIn = productIsIn();
return prodIn;
}, },
'edit.product' (prodId, prodName, prodStore) { async 'edit.product' (prodId, prodName, prodStore) {
check(prodId, String); check(prodId, String);
check(prodName, String); check(prodName, String);
check(prodStore, [String]); check(prodStore, [String]);
@ -52,20 +48,20 @@ Meteor.methods({
let pname = prodName.charAt(0).toUpperCase() + prodName.slice(1); let pname = prodName.charAt(0).toUpperCase() + prodName.slice(1);
return Products.updateAsync({ _id: prodId }, { return await Products.updateAsync({ _id: prodId }, {
$set: { $set: {
prodName: pname, prodName: pname,
prodStore: prodStore, prodStore: prodStore,
} }
}); });
}, },
'delete.product' (prodId) { async 'delete.product' (prodId) {
check(prodId, String); check(prodId, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete products. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to delete products. Make sure you are logged in with valid user credentials.');
} }
return Products.removeAsync({ _id: prodId }); return await Products.removeAsync({ _id: prodId });
} }
}); });

View file

@ -12,7 +12,7 @@ RecipeItems.allow({
}); });
Meteor.methods({ Meteor.methods({
'add.recipeItem' (recipeId, recipeItemType, recipeItem) { async 'add.recipeItem' (recipeId, recipeItemType, recipeItem) {
check(recipeId, String); check(recipeId, String);
check(recipeItemType, String); check(recipeItemType, String);
check(recipeItem, String); check(recipeItem, String);
@ -21,13 +21,13 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to add recipe items. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to add recipe items. Make sure you are logged in with valid user credentials.');
} }
return RecipeItems.insertAsync({ return await RecipeItems.insertAsync({
recipeId: recipeId, recipeId: recipeId,
recipeItemType: recipeItemType, recipeItemType: recipeItemType,
recipeItem: recipeItem, recipeItem: recipeItem,
}); });
}, },
'edit.recipeItem' (recipeItemId, recipeId, recipeItemType, recipeItem) { async 'edit.recipeItem' (recipeItemId, recipeId, recipeItemType, recipeItem) {
check(recipeItemId, String); check(recipeItemId, String);
check(recipeId, String); check(recipeId, String);
check(recipeItemType, String); check(recipeItemType, String);
@ -37,7 +37,7 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to edit recipe items. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to edit recipe items. Make sure you are logged in with valid user credentials.');
} }
return RecipeItems.updateAsync({ _id: recipeItemId }, { return await RecipeItems.updateAsync({ _id: recipeItemId }, {
$set: { $set: {
recipeId: recipeId, recipeId: recipeId,
recipeItemType: recipeItemType, recipeItemType: recipeItemType,
@ -45,13 +45,13 @@ Meteor.methods({
} }
}); });
}, },
'delete.recipeItem' (recipeItemId) { async 'delete.recipeItem' (recipeItemId) {
check(recipeItemId, String); check(recipeItemId, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete recipe items. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to delete recipe items. Make sure you are logged in with valid user credentials.');
} }
return RecipeItems.removeAsync({ _id: recipeItemId }); return await RecipeItems.removeAsync({ _id: recipeItemId });
} }
}); });

View file

@ -12,20 +12,20 @@ Recipes.allow({
}); });
Meteor.methods({ Meteor.methods({
'add.recipe' (recipeName) { async 'add.recipe' (recipeName) {
check(recipeName, String); check(recipeName, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to add recipes. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to add recipes. Make sure you are logged in with valid user credentials.');
} }
return Recipes.insertAsync({ return await Recipes.insertAsync({
recipeName: recipeName, recipeName: recipeName,
addedBy: this.userId, addedBy: this.userId,
addedOn: new Date(), addedOn: new Date(),
}); });
}, },
'edit.recipe' (recipeId, recipeName) { async 'edit.recipe' (recipeId, recipeName) {
check(recipeId, String); check(recipeId, String);
check(recipeName, String); check(recipeName, String);
@ -33,7 +33,7 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to add recipes. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to add recipes. Make sure you are logged in with valid user credentials.');
} }
return Recipes.updateAsync({ _id: recipeId }, { return await Recipes.updateAsync({ _id: recipeId }, {
$set: { $set: {
recipeName: recipeName, recipeName: recipeName,
updatedOn: new Date(), updatedOn: new Date(),
@ -41,13 +41,13 @@ Meteor.methods({
} }
}); });
}, },
'delete.recipe' (recipeId) { async 'delete.recipe' (recipeId) {
check(recipeId, String); check(recipeId, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete recipes. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to delete recipes. Make sure you are logged in with valid user credentials.');
} }
return Recipes.removeAsync({ _id: recipeId }); return await Recipes.removeAsync({ _id: recipeId });
} }
}); });

View file

@ -12,19 +12,19 @@ ShopLists.allow({
}); });
Meteor.methods({ Meteor.methods({
'add.shopList' (shopName) { async 'add.shopList' (shopName) {
check(shopName, Sring); check(shopName, Sring);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to add shopping lists. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to add shopping lists. Make sure you are logged in with valid user credentials.');
} }
return ShopLists.insert({ return await ShopLists.insert({
shopName: shopName, shopName: shopName,
shopOwner: this.userId, shopOwner: this.userId,
}); });
}, },
'edit.shopList' (shopId, shopName) { async 'edit.shopList' (shopId, shopName) {
check(shopId, String); check(shopId, String);
check(shopName, String); check(shopName, String);
@ -32,19 +32,19 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to edit shopping lists. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to edit shopping lists. Make sure you are logged in with valid user credentials.');
} }
return ShopLists.update({ _id: shopId }, { return await ShopLists.update({ _id: shopId }, {
$set: { $set: {
shopName: shopName, shopName: shopName,
} }
}); });
}, },
'delete.shopList' (shopId) { async 'delete.shopList' (shopId) {
check(shopId, String); check(shopId, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete shopping lists. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to delete shopping lists. Make sure you are logged in with valid user credentials.');
} }
return ShopLists.remove({ _id: shopId }); return await ShopLists.remove({ _id: shopId });
}, },
}); });

View file

@ -12,19 +12,19 @@ Stores.allow({
}); });
Meteor.methods({ Meteor.methods({
'add.store' (storeName) { async 'add.store' (storeName) {
check(storeName, String); check(storeName, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to add stores. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to add stores. Make sure you are logged in with valid user credentials.');
} }
return Stores.insertAsync({ return await Stores.insertAsync({
storeName: storeName, storeName: storeName,
owner: this.userId, owner: this.userId,
}); });
}, },
'edit.store' (storeId, storeName) { async 'edit.store' (storeId, storeName) {
check(storeId, String); check(storeId, String);
check(storeName, String); check(storeName, String);
@ -32,19 +32,19 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to edit stores. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to edit stores. Make sure you are logged in with valid user credentials.');
} }
return Stores.updateAsync({ _id: storeId }, { return await Stores.updateAsync({ _id: storeId }, {
$set: { $set: {
storeName: storeName, storeName: storeName,
} }
}); });
}, },
'delete.store' (storeId) { async 'delete.store' (storeId) {
check(storeId, String); check(storeId, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete stores. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to delete stores. Make sure you are logged in with valid user credentials.');
} }
return Stores.removeAsync({ _id: storeId }); return await Stores.removeAsync({ _id: storeId });
}, },
}); });

View file

@ -12,7 +12,7 @@ SysConfig.allow({
}); });
Meteor.methods({ Meteor.methods({
'add.noSysAdminReg' (admReg, genReg) { async 'add.noSysAdminReg' (admReg, genReg) {
check(admReg, Boolean); check(admReg, Boolean);
check(genReg, Boolean); check(genReg, Boolean);
@ -24,7 +24,7 @@ Meteor.methods({
let curr = await SysConfig.findOneAsync({}); let curr = await SysConfig.findOneAsync({});
if (!curr) { if (!curr) {
try { try {
return SysConfig.insertAsync({ return await SysConfig.insertAsync({
SysAdminReg: admReg, SysAdminReg: admReg,
dateAdded: new Date(), dateAdded: new Date(),
allowReg: genReg, allowReg: genReg,
@ -52,7 +52,7 @@ Meteor.methods({
} }
currConfig(); currConfig();
}, },
'edit.noSysAdminReg' (configId, canReg, genReg) { async 'edit.noSysAdminReg' (configId, canReg, genReg) {
check(canReg, Boolean); check(canReg, Boolean);
check(configId, String); check(configId, String);
check(genReg, Boolean); check(genReg, Boolean);
@ -61,7 +61,7 @@ Meteor.methods({
throw new Meteor.Error('Not able to change registration setting. Make sure you are logged in with valid system administrator credentials.'); throw new Meteor.Error('Not able to change registration setting. Make sure you are logged in with valid system administrator credentials.');
} }
return SysConfig.updateAsync({ _id: configId }, { return await SysConfig.updateAsync({ _id: configId }, {
$set: { $set: {
SysAdminReg: canReg, SysAdminReg: canReg,
allowReg: genReg, allowReg: genReg,
@ -69,7 +69,7 @@ Meteor.methods({
} }
}); });
}, },
'allow.updateInfo' (allowUpdate) { async 'allow.updateInfo' (allowUpdate) {
check(allowUpdate, Boolean); check(allowUpdate, Boolean);
if (!this.userId) { if (!this.userId) {
@ -80,7 +80,7 @@ Meteor.methods({
let configId = curr._id; let configId = curr._id;
return SysConfig.updateAsync({ _id: configId }, { return await SysConfig.updateAsync({ _id: configId }, {
$set: { $set: {
allowUpdates: allowUpdate, allowUpdates: allowUpdate,
} }

View file

@ -12,24 +12,24 @@ UpdateInfo.allow({
}); });
Meteor.methods({ Meteor.methods({
'add.updateInfo' (updateObject) { async 'add.updateInfo' (updateObject) {
check(updateObject, Object); check(updateObject, Object);
return UpdateInfo.insertAsync({ return await UpdateInfo.insertAsync({
title: updateObject.title, title: updateObject.title,
description: updateObject.description, description: updateObject.description,
dateRelease: updateObject.date, dateRelease: updateObject.date,
releaseLink: updateObject.link releaseLink: updateObject.link
}); });
}, },
'markUpdate.read' (updateId) { async 'markUpdate.read' (updateId) {
check(updateId, String); check(updateId, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('You are not allowed to mark updates as read. Make sure you are logged in with valid user credentials.'); throw new Meteor.Error('You are not allowed to mark updates as read. Make sure you are logged in with valid user credentials.');
} }
return UpdateInfo.updateAsync({ _id: updateId }, { return await UpdateInfo.updateAsync({ _id: updateId }, {
$set: { $set: {
viewed: true viewed: true
} }

View file

@ -16,27 +16,27 @@ UserConfig.allow({
}); });
Meteor.methods({ Meteor.methods({
'add.darkModePref' (pref) { async 'add.darkModePref' (pref) {
check(pref, String); check(pref, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('Not able to change theme setting. Make sure you are logged in with valid system administrator credentials.'); throw new Meteor.Error('Not able to change theme setting. Make sure you are logged in with valid system administrator credentials.');
} }
return UserConfig.insertAsync({ return await UserConfig.insertAsync({
user: this.userId, user: this.userId,
darkMode: pref, darkMode: pref,
dateAdded: Date() dateAdded: Date()
}); });
}, },
'update.darkModePref' (pref) { async 'update.darkModePref' (pref) {
check(pref, String); check(pref, String);
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error('Not able to change theme setting. Make sure you are logged in with valid system administrator credentials.'); throw new Meteor.Error('Not able to change theme setting. Make sure you are logged in with valid system administrator credentials.');
} }
return UserConfig.updateAsync({ user: this.userId }, { return await UserConfig.updateAsync({ user: this.userId }, {
$set: { $set: {
darkMode: pref, darkMode: pref,
dateUpdate: Date() dateUpdate: Date()

View file

@ -12,10 +12,10 @@ UserConfigOptions.allow({
}); });
Meteor.methods({ Meteor.methods({
'change.userPass' (usersId, password) { async 'change.userPass' (usersId, password) {
check(usersId, String); check(usersId, String);
check(password, String); check(password, String);
return Accounts.setPasswordAsync(usersId, password); return await Accounts.setPasswordAsync(usersId, password);
}, },
}); });

View file

@ -12,7 +12,7 @@ UserLast.allow({
}); });
Meteor.methods({ Meteor.methods({
'add.userLast' (view, viewId) { async 'add.userLast' (view, viewId) {
check(view, String); check(view, String);
check(viewId, String); check(viewId, String);
@ -22,11 +22,10 @@ Meteor.methods({
// first let's find out if there's an entry for this user and view, and if so // first let's find out if there's an entry for this user and view, and if so
// we'll just edit that entry with updated information // we'll just edit that entry with updated information
const getUserLast = async() => {
let userListInfo = await UserLast.findOneAsync({ userId: this.userId, view: view }); let userListInfo = await UserLast.findOneAsync({ userId: this.userId, view: view });
if (!userListInfo) { if (!userListInfo) {
console.log("Adding new user last item."); console.log("Adding new user last item.");
return UserLast.insertAsync({ return await UserLast.insertAsync({
userId: this.userId, userId: this.userId,
view: view, view: view,
viewId: viewId, viewId: viewId,
@ -48,10 +47,8 @@ Meteor.methods({
return true; return true;
} }
} }
}
return getUserLast();
}, },
'edit.userLast' (view, viewId) { async 'edit.userLast' (view, viewId) {
check(view, String); check(view, String);
check(viewId, String); check(viewId, String);
@ -60,7 +57,7 @@ Meteor.methods({
} }
console.log("Edit in progress."); console.log("Edit in progress.");
return UserLast.updateAsync({ view: view, userId: this.userId }, { return await UserLast.updateAsync({ view: view, userId: this.userId }, {
$set: { $set: {
viewId: viewId, viewId: viewId,
dateLastUpdate: Date(), dateLastUpdate: Date(),

View file

@ -6,15 +6,14 @@ import { SysConfig } from '../imports/api/systemConfig';
import { Roles } from 'meteor/roles'; import { Roles } from 'meteor/roles';
Meteor.methods({ Meteor.methods({
'addToRole' (role) { async 'addToRole' (role) {
const getUserInfo = async() => {
try { try {
let countOfUsers = await Meteor.users.find().countAsync(); let countOfUsers = await Meteor.users.find().countAsync();
const user = await Meteor.userAsync(); const user = await Meteor.userAsync();
if (user) { if (user) {
let userId = user._id; let userId = user._id;
if (countOfUsers > 1) { if (countOfUsers > 1) {
Roles.addUsersToRolesAsync(userId, role); await Roles.addUsersToRolesAsync(userId, role);
const result = await Meteor.callAsync('add.darkModePref', "light"); const result = await Meteor.callAsync('add.darkModePref', "light");
if (!result) { if (!result) {
console.log(" ERROR: can't set user dark mode preference: " + err); console.log(" ERROR: can't set user dark mode preference: " + err);
@ -22,7 +21,7 @@ Meteor.methods({
// console.log(" SUCCESSFULLY set user dark mode preference."); // console.log(" SUCCESSFULLY set user dark mode preference.");
} }
} else if (countOfUsers == 1) { } else if (countOfUsers == 1) {
Roles.addUsersToRolesAsync(userId, "systemadmin"); await Roles.addUsersToRolesAsync(userId, "systemadmin");
const result = await Meteor.callAsync('add.darkModePref', "light"); const result = await Meteor.callAsync('add.darkModePref', "light");
if (!result) { if (!result) {
console.log(" ERROR: can't set user dark mode preference: " + err); console.log(" ERROR: can't set user dark mode preference: " + err);
@ -38,34 +37,32 @@ Meteor.methods({
} catch(error) { } catch(error) {
console.log(" ERROR getting user info on server: " + error); console.log(" ERROR getting user info on server: " + error);
} }
}
getUserInfo();
}, },
'edit.userPass' (userId, newPassword) { async 'edit.userPass' (userId, newPassword) {
check(userId, String); check(userId, String);
check(newPassword, String); check(newPassword, String);
return Accounts.setPasswordAsync(userId, newPassword); return await Accounts.setPasswordAsync(userId, newPassword);
}, },
'delete.userFromSys' (userId) { async 'delete.userFromSys' (userId) {
check(userId, String); check(userId, String);
return Meteor.users.removeAsync({ _id: userId }); return await Meteor.users.removeAsync({ _id: userId });
}, },
'update.userEmail' (userId, email) { async 'update.userEmail' (userId, email) {
check(userId, String); check(userId, String);
check(email, String); check(email, String);
return Meteor.users.updateAsync({ _id: userId }, { return await Meteor.users.updateAsync({ _id: userId }, {
$set: { $set: {
'emails.0.address': email, 'emails.0.address': email,
} }
}); });
}, },
'edit.userRole' (userId, role) { async 'edit.userRole' (userId, role) {
check(userId, String); check(userId, String);
check(role, String); check(role, String);
return Roles.setUserRolesAsync(userId, role); return await Roles.setUserRolesAsync(userId, role);
}, },
}); });