From 706c5dc3ef65f3ea8b6a2a61bc7d351bbc861907 Mon Sep 17 00:00:00 2001 From: Brian McGonagill Date: Tue, 22 Jul 2025 13:50:49 -0500 Subject: [PATCH] Updates for async and await - still --- client/AdminMgmt/ListMgmt/listMgmtForm.js | 6 +- imports/api/listItems.js | 119 +++++++++++----------- imports/api/lists.js | 24 ++--- imports/api/mScripts.js | 4 +- imports/api/menu.js | 36 +++---- imports/api/menuItems.js | 20 ++-- imports/api/menuProdLinks.js | 8 +- imports/api/products.js | 34 +++---- imports/api/recipeItems.js | 12 +-- imports/api/recipes.js | 12 +-- imports/api/shopList.js | 12 +-- imports/api/stores.js | 12 +-- imports/api/systemConfig.js | 12 +-- imports/api/updateInfo.js | 8 +- imports/api/userConfig.js | 8 +- imports/api/userConfigOptions.js | 4 +- imports/api/userLast.js | 53 +++++----- server/methods.js | 69 ++++++------- 18 files changed, 220 insertions(+), 233 deletions(-) diff --git a/client/AdminMgmt/ListMgmt/listMgmtForm.js b/client/AdminMgmt/ListMgmt/listMgmtForm.js index 509a4c6..75a01c3 100644 --- a/client/AdminMgmt/ListMgmt/listMgmtForm.js +++ b/client/AdminMgmt/ListMgmt/listMgmtForm.js @@ -71,9 +71,8 @@ Template.listMgmtForm.events({ const addList = async(listName, shared) => { let result = await Meteor.callAsync('add.list', listName, shared); if (!result) { - // console.log(" ERROR adding list name: "); + console.log("Nothing returned from method call add.list"); } else { - // console.log(" SUCCESS adding list name."); $("#listNameInp").val(""); $("#isShared").prop("checked", false); } @@ -82,9 +81,8 @@ const addList = async(listName, shared) => { const editList = async(listId, listName, shared) => { let result = await Meteor.callAsync('edit.list', listId, listName, shared); if (!result) { - // console.log(" ERROR editing list name: " + err); + // console.log("Nothing returned from method call edit.list"); } else { - // console.log(" SUCCESS editing list name."); $("#listNameInp").val(""); $("#isShared").prop("checked", false); Session.set("listNameEditMode", false); diff --git a/imports/api/listItems.js b/imports/api/listItems.js index 7f3ff0c..eb66875 100644 --- a/imports/api/listItems.js +++ b/imports/api/listItems.js @@ -14,7 +14,7 @@ ListItems.allow({ }); Meteor.methods({ - 'add.listItem' (itemName, listId) { + async 'add.listItem' (itemName, listId) { check(itemName, String); check(listId, String); @@ -25,50 +25,45 @@ Meteor.methods({ let iname = itemName.charAt(0).toUpperCase() + itemName.slice(1); // look up the item from the Products collection - const prodIsIn = async() => { - let prodInfo = await Products.findOneAsync({ prodName: iname }); - try { - if (!prodInfo) { - // add product info first - const addProd = async() => { - let added = await Meteor.callAsync("add.product", itemName, [""]); - if (!added) { - console.log(" ERROR adding item to products: " + err); - } else { - // console.log(" SUCCESS adding item to Products."); - - return ListItems.insertAsync({ - itemName: iname, - listId: listId, - prodId: result, - addedBy: this.userId, - itemStore: "", - itemOrdered: false, - itemReceived: false, - dateAddedToList: new Date(), - }); - } - } + + let prodInfo = await Products.findOneAsync({ prodName: iname }); + try { + if (!prodInfo) { + // add product info first + let added = await Meteor.callAsync("add.product", itemName, [""]); + if (!added) { + console.log(" ERROR adding item to products: " + err); } else { - return ListItems.insertAsync({ + // console.log(" SUCCESS adding item to Products."); + + return await ListItems.insertAsync({ itemName: iname, listId: listId, - prodId: prodInfo._id, + prodId: result, addedBy: this.userId, - itemStore: prodInfo.prodStore, + itemStore: "", itemOrdered: false, itemReceived: false, dateAddedToList: new Date(), }); } - } catch(error) { - console.log(" ERROR adding new product and item: " + error); + } else { + return await ListItems.insertAsync({ + itemName: iname, + listId: listId, + prodId: prodInfo._id, + addedBy: this.userId, + itemStore: prodInfo.prodStore, + itemOrdered: false, + itemReceived: false, + dateAddedToList: new Date(), + }); } + } catch(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(listId, String); @@ -80,67 +75,71 @@ Meteor.methods({ 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); + let onList = await 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.insertAsync({ - itemName: prodInfo.prodName, - listId: listId, - prodId: prodInfo._id, - addedBy: this.userId, - itemStore: prodInfo.prodStore, - itemOrdered: false, - itemReceived: false, - dateAddedToList: new Date(), - }); + let prodInfo = await Products.findOneAsync({ _id: itemIds[i] }); + if (!prodInfo) { + console.log("Unable to load product info."); + } else { + ListItems.insertAsync({ + 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) { + async 'setOrdered.listItem' (itemId) { check(itemId, String); 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.'); } - return ListItems.updateAsync({ _id: itemId }, { + return await ListItems.updateAsync({ _id: itemId }, { $set: { itemOrdered: true, 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 }, - 'setNotOrdered.listItem' (itemId) { + async 'setNotOrdered.listItem' (itemId) { check(itemId, String); 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.'); } - return ListItems.updateAsync({ _id: itemId }, { + return await ListItems.updateAsync({ _id: itemId }, { $set: { itemOrdered: false, dateUnOrdered: new Date(), } }); }, - 'setReceived.listItem' (itemId) { + async 'setReceived.listItem' (itemId) { check(itemId, String); 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.'); } - return ListItems.updateAsync({ _id: itemId }, { + return await ListItems.updateAsync({ _id: itemId }, { $set: { itemReceived: true, dateReceived: new Date(), @@ -148,25 +147,25 @@ Meteor.methods({ }); }, - 'setNotReceived.listItem' (shopListId) { + async 'setNotReceived.listItem' (shopListId) { check(itemId, String); 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.'); } - return ListItems.updateAsync({ _id: itemId }, { + return await ListItems.updateAsync({ _id: itemId }, { $set: { itemReceived: false, dateNotReceived: new Date(), } }); }, - 'setAllReceived.listItem' () { + async 'setAllReceived.listItem' () { // 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(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.'); } - return ListItems.updateAsync({ _id: itemId }, { + return await ListItems.updateAsync({ _id: itemId }, { $set: { itemName: itemName, } }); }, - 'delete.listItem' (itemId) { + async 'delete.listItem' (itemId) { check(itemId, String); 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.'); } - return ListItems.removeAsync({ _id: itemId }); + return await ListItems.removeAsync({ _id: itemId }); } }); diff --git a/imports/api/lists.js b/imports/api/lists.js index 037e73e..65f2f5d 100644 --- a/imports/api/lists.js +++ b/imports/api/lists.js @@ -12,7 +12,7 @@ Lists.allow({ }); Meteor.methods({ - 'add.list' (listName, isShared) { + async 'add.list' (listName, isShared) { check(listName, String); 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.'); } - return Lists.insertAsync({ + return await Lists.insertAsync({ listName: listName, listShared: isShared, listOwner: this.userId, listComplete: false, }); }, - 'edit.list' (listId, listName, isShared) { + async 'edit.list' (listId, listName, isShared) { check(listId, String); check(listName, String); 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.'); } - return Lists.updateAsync({ _id: listId }, { + return await Lists.updateAsync({ _id: listId }, { $set: { listName: listName, listShared: isShared, } }); }, - 'delete.list' (listId) { + async 'delete.list' (listId) { check(listId, String); if (!this.userId) { 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); 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.'); } - return Lists.updateAsync({ _id: listId }, { + return await Lists.updateAsync({ _id: listId }, { $set: { listComplete: true, completedOn: new Date() } }); }, - 'mark.incomplete' (listId) { + async 'mark.incomplete' (listId) { check(listId, String); 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.'); } - return Lists.updateAsync({ _id: listId }, { + return await Lists.updateAsync({ _id: listId }, { $set: { listComplete: false, completedOn: new Date() } }); }, - 'clean.Lists' () { + async 'clean.Lists' () { 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.'); } - return Lists.removeAsync({ listComplete: true }); + return await Lists.removeAsync({ listComplete: true }); }, }); \ No newline at end of file diff --git a/imports/api/mScripts.js b/imports/api/mScripts.js index 710c530..67c1685 100644 --- a/imports/api/mScripts.js +++ b/imports/api/mScripts.js @@ -12,10 +12,10 @@ MScripts.allow({ }); Meteor.methods({ - 'set.ScriptRun' (scriptName) { + async 'set.ScriptRun' (scriptName) { check(scriptName, String); - MScripts.insertAsync({ + return await MScripts.insertAsync({ scriptName: scriptName, hasRun: true, runOn: new Date(), diff --git a/imports/api/menu.js b/imports/api/menu.js index 7ea3be2..cf3b8eb 100644 --- a/imports/api/menu.js +++ b/imports/api/menu.js @@ -15,20 +15,20 @@ Menus.allow({ }); Meteor.methods({ - 'add.menu' (menuName) { + async 'add.menu' (menuName) { check(menuName, String); if (!this.userId) { 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, menuOwner: this.userId, menuComplete: false, }); }, - 'edit.menu' (menuId, menuName) { + async 'edit.menu' (menuId, menuName) { check(menuId, 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.'); } - return Menus.updateAsync({ _id: menuId }, { + return await Menus.updateAsync({ _id: menuId }, { $set: { menuName: menuName, } }); }, - 'delete.menu' (menuId) { + async 'delete.menu' (menuId) { check(menuId, String); if (!this.userId) { 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); 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.'); } - return Menus.updateAsync({ _id: menuId }, { + return await Menus.updateAsync({ _id: menuId }, { $set: { menuComplete: true, } }); }, - 'markMenu.notComplete' (menuId) { + async 'markMenu.notComplete' (menuId) { check(menuId, String); 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.'); } - return Menus.updateAsync({ _id: menuId }, { + return await Menus.updateAsync({ _id: menuId }, { $set: { menuComplete: false, } }); }, - 'clean.Menus' () { + async 'clean.Menus' () { 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.'); } @@ -114,10 +114,10 @@ Meteor.methods({ // finally we'll cycle through the ids and remove the items we collected up. 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(menuItem, String); check(menuItemId, String); @@ -130,7 +130,7 @@ Meteor.methods({ let serveDateActual = new Date(dateSrv); - return Menus.updateAsync({ _id: menuId }, { + return await Menus.updateAsync({ _id: menuId }, { $addToSet: { menuItems: { @@ -143,7 +143,7 @@ Meteor.methods({ } }); }, - 'link.inMenu' (menuItemId, isLinked) { + async 'link.inMenu' (menuItemId, isLinked) { check(menuItemId, String); 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.'); } - return Menus.updateAsync({ 'menuItems.menuItemId': menuItemId }, { + return await Menus.updateAsync({ 'menuItems.menuItemId': menuItemId }, { $set: { "menuItems.$.isLinked": isLinked } }); }, - 'delete.itemFromMenu' (itemIds) { + async 'delete.itemFromMenu' (itemIds) { check(itemIds, String); if (!this.userId) { @@ -167,7 +167,7 @@ Meteor.methods({ let ids = itemIds.split('_'); console.log("item ids: " + ids[0] + " and " + ids[1]); - return Menus.updateAsync({ _id: ids[0] }, { + return await Menus.updateAsync({ _id: ids[0] }, { $pull: { menuItems: { menuItemId: ids[1], diff --git a/imports/api/menuItems.js b/imports/api/menuItems.js index 69f47fe..232d510 100644 --- a/imports/api/menuItems.js +++ b/imports/api/menuItems.js @@ -12,21 +12,21 @@ MenuItems.allow({ }); Meteor.methods({ - 'add.menuItem' (itemName) { + async 'add.menuItem' (itemName) { check(itemName, 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.'); } - return MenuItems.insertAsync({ + return await MenuItems.insertAsync({ itemName: itemName, addedBy: this.userId, dateAddedtoMenu: new Date(), isLinked: false, }); }, - 'update.menuItemLinked' (itemId, isLinked) { + async 'update.menuItemLinked' (itemId, isLinked) { check(itemId, String); 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.'); } - return MenuItems.updateAsync({ _id: itemId }, { + return await MenuItems.updateAsync({ _id: itemId }, { $set: { isLinked: isLinked, } }); }, - 'edit.madeItem' (itemId, itemName) { + async 'edit.madeItem' (itemId, itemName) { check(itemId, 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.'); } - return MenuItems.updateAsync({ _id: itemId }, { + return await MenuItems.updateAsync({ _id: itemId }, { $set: { itemName: itemName, } }); }, - 'delete.menuItem' (itemId) { + async 'delete.menuItem' (itemId) { check(itemId, String); 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.'); } - return MenuItems.removeAsync({ _id: itemId }); + return await MenuItems.removeAsync({ _id: itemId }); }, - 'shiftDate' (itemId, momentAddDay) { + async 'shiftDate' (itemId, momentAddDay) { check(itemId, 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.'); } - return MenuItems.updateAsync({ _id: itemId }, { + return await MenuItems.updateAsync({ _id: itemId }, { $set: { serveDate: momentAddDay, } diff --git a/imports/api/menuProdLinks.js b/imports/api/menuProdLinks.js index 0a9b2de..9cfe22a 100644 --- a/imports/api/menuProdLinks.js +++ b/imports/api/menuProdLinks.js @@ -13,7 +13,7 @@ MenuProdLinks.allow({ }); Meteor.methods({ - 'add.menuProdLinks' (menuItemId, menuItemName, prodNameArray) { + async 'add.menuProdLinks' (menuItemId, menuItemName, prodNameArray) { check(menuItemId, String); check(menuItemName, String); check(prodNameArray, [Object]); @@ -34,7 +34,7 @@ Meteor.methods({ } }); } else { - return MenuProdLinks.insertAsync({ + return await MenuProdLinks.insertAsync({ menuItemId: menuItemId, menuItemName: menuItemName, products: prodNameArray, @@ -43,7 +43,7 @@ Meteor.methods({ }); } }, - 'update.menuPordLInks' (menuItemId, menuItemName, prodNameArray) { + async 'update.menuPordLInks' (menuItemId, menuItemName, prodNameArray) { check(menuItemId, String); check(menuItemName, String); 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.'); }; - return MenuProdLinks.updateAsync({ menuItemId: menuItemId }, { + return await MenuProdLinks.updateAsync({ menuItemId: menuItemId }, { $set: { products: prodNameArray, dateUpdated: Date(), diff --git a/imports/api/products.js b/imports/api/products.js index 3eafefa..b8d5056 100644 --- a/imports/api/products.js +++ b/imports/api/products.js @@ -12,7 +12,7 @@ Products.allow({ }); Meteor.methods({ - 'add.product' (prodName, prodStore) { + async 'add.product' (prodName, prodStore) { check(prodName, String); check(prodStore, [String]); @@ -24,24 +24,20 @@ Meteor.methods({ // first does this product already exist? - const productIsIn = async() => { - let prodExists = await Products.findOneAsync({ prodName: pname }); - try { - if (!prodExists) { - return Products.insertAsync({ - prodName: pname, - prodOwner: this.userId, - prodStore: prodStore, - }); - } - } catch(error) { - console.log(" ERROR adding Pdocut: " + error); + let prodExists = await Products.findOneAsync({ prodName: pname }); + try { + if (!prodExists) { + return await Products.insertAsync({ + prodName: pname, + prodOwner: this.userId, + prodStore: prodStore, + }); } + } catch(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(prodName, String); check(prodStore, [String]); @@ -52,20 +48,20 @@ Meteor.methods({ let pname = prodName.charAt(0).toUpperCase() + prodName.slice(1); - return Products.updateAsync({ _id: prodId }, { + return await Products.updateAsync({ _id: prodId }, { $set: { prodName: pname, prodStore: prodStore, } }); }, - 'delete.product' (prodId) { + async 'delete.product' (prodId) { check(prodId, String); if (!this.userId) { 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 }); } }); diff --git a/imports/api/recipeItems.js b/imports/api/recipeItems.js index b19a0ea..42b374f 100644 --- a/imports/api/recipeItems.js +++ b/imports/api/recipeItems.js @@ -12,7 +12,7 @@ RecipeItems.allow({ }); Meteor.methods({ - 'add.recipeItem' (recipeId, recipeItemType, recipeItem) { + async 'add.recipeItem' (recipeId, recipeItemType, recipeItem) { check(recipeId, String); check(recipeItemType, 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.'); } - return RecipeItems.insertAsync({ + return await RecipeItems.insertAsync({ recipeId: recipeId, recipeItemType: recipeItemType, recipeItem: recipeItem, }); }, - 'edit.recipeItem' (recipeItemId, recipeId, recipeItemType, recipeItem) { + async 'edit.recipeItem' (recipeItemId, recipeId, recipeItemType, recipeItem) { check(recipeItemId, String); check(recipeId, 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.'); } - return RecipeItems.updateAsync({ _id: recipeItemId }, { + return await RecipeItems.updateAsync({ _id: recipeItemId }, { $set: { recipeId: recipeId, recipeItemType: recipeItemType, @@ -45,13 +45,13 @@ Meteor.methods({ } }); }, - 'delete.recipeItem' (recipeItemId) { + async 'delete.recipeItem' (recipeItemId) { check(recipeItemId, String); 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.'); } - return RecipeItems.removeAsync({ _id: recipeItemId }); + return await RecipeItems.removeAsync({ _id: recipeItemId }); } }); \ No newline at end of file diff --git a/imports/api/recipes.js b/imports/api/recipes.js index d1edbe3..008bb51 100644 --- a/imports/api/recipes.js +++ b/imports/api/recipes.js @@ -12,20 +12,20 @@ Recipes.allow({ }); Meteor.methods({ - 'add.recipe' (recipeName) { + async 'add.recipe' (recipeName) { check(recipeName, String); if (!this.userId) { 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, addedBy: this.userId, addedOn: new Date(), }); }, - 'edit.recipe' (recipeId, recipeName) { + async 'edit.recipe' (recipeId, recipeName) { check(recipeId, 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.'); } - return Recipes.updateAsync({ _id: recipeId }, { + return await Recipes.updateAsync({ _id: recipeId }, { $set: { recipeName: recipeName, updatedOn: new Date(), @@ -41,13 +41,13 @@ Meteor.methods({ } }); }, - 'delete.recipe' (recipeId) { + async 'delete.recipe' (recipeId) { check(recipeId, String); if (!this.userId) { 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 }); } }); \ No newline at end of file diff --git a/imports/api/shopList.js b/imports/api/shopList.js index b013d50..637e740 100644 --- a/imports/api/shopList.js +++ b/imports/api/shopList.js @@ -12,19 +12,19 @@ ShopLists.allow({ }); Meteor.methods({ - 'add.shopList' (shopName) { + async 'add.shopList' (shopName) { check(shopName, Sring); 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.'); } - return ShopLists.insert({ + return await ShopLists.insert({ shopName: shopName, shopOwner: this.userId, }); }, - 'edit.shopList' (shopId, shopName) { + async 'edit.shopList' (shopId, shopName) { check(shopId, 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.'); } - return ShopLists.update({ _id: shopId }, { + return await ShopLists.update({ _id: shopId }, { $set: { shopName: shopName, } }); }, - 'delete.shopList' (shopId) { + async 'delete.shopList' (shopId) { check(shopId, String); 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.'); } - return ShopLists.remove({ _id: shopId }); + return await ShopLists.remove({ _id: shopId }); }, }); \ No newline at end of file diff --git a/imports/api/stores.js b/imports/api/stores.js index b0fbec9..c97b381 100644 --- a/imports/api/stores.js +++ b/imports/api/stores.js @@ -12,19 +12,19 @@ Stores.allow({ }); Meteor.methods({ - 'add.store' (storeName) { + async 'add.store' (storeName) { check(storeName, String); if (!this.userId) { 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, owner: this.userId, }); }, - 'edit.store' (storeId, storeName) { + async 'edit.store' (storeId, storeName) { check(storeId, 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.'); } - return Stores.updateAsync({ _id: storeId }, { + return await Stores.updateAsync({ _id: storeId }, { $set: { storeName: storeName, } }); }, - 'delete.store' (storeId) { + async 'delete.store' (storeId) { check(storeId, String); if (!this.userId) { 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 }); }, }); \ No newline at end of file diff --git a/imports/api/systemConfig.js b/imports/api/systemConfig.js index 7188ebd..a278007 100644 --- a/imports/api/systemConfig.js +++ b/imports/api/systemConfig.js @@ -12,7 +12,7 @@ SysConfig.allow({ }); Meteor.methods({ - 'add.noSysAdminReg' (admReg, genReg) { + async 'add.noSysAdminReg' (admReg, genReg) { check(admReg, Boolean); check(genReg, Boolean); @@ -24,7 +24,7 @@ Meteor.methods({ let curr = await SysConfig.findOneAsync({}); if (!curr) { try { - return SysConfig.insertAsync({ + return await SysConfig.insertAsync({ SysAdminReg: admReg, dateAdded: new Date(), allowReg: genReg, @@ -52,7 +52,7 @@ Meteor.methods({ } currConfig(); }, - 'edit.noSysAdminReg' (configId, canReg, genReg) { + async 'edit.noSysAdminReg' (configId, canReg, genReg) { check(canReg, Boolean); check(configId, String); 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.'); } - return SysConfig.updateAsync({ _id: configId }, { + return await SysConfig.updateAsync({ _id: configId }, { $set: { SysAdminReg: canReg, allowReg: genReg, @@ -69,7 +69,7 @@ Meteor.methods({ } }); }, - 'allow.updateInfo' (allowUpdate) { + async 'allow.updateInfo' (allowUpdate) { check(allowUpdate, Boolean); if (!this.userId) { @@ -80,7 +80,7 @@ Meteor.methods({ let configId = curr._id; - return SysConfig.updateAsync({ _id: configId }, { + return await SysConfig.updateAsync({ _id: configId }, { $set: { allowUpdates: allowUpdate, } diff --git a/imports/api/updateInfo.js b/imports/api/updateInfo.js index 4fd9faa..34f222b 100644 --- a/imports/api/updateInfo.js +++ b/imports/api/updateInfo.js @@ -12,24 +12,24 @@ UpdateInfo.allow({ }); Meteor.methods({ - 'add.updateInfo' (updateObject) { + async 'add.updateInfo' (updateObject) { check(updateObject, Object); - return UpdateInfo.insertAsync({ + return await UpdateInfo.insertAsync({ title: updateObject.title, description: updateObject.description, dateRelease: updateObject.date, releaseLink: updateObject.link }); }, - 'markUpdate.read' (updateId) { + async 'markUpdate.read' (updateId) { check(updateId, String); 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.'); } - return UpdateInfo.updateAsync({ _id: updateId }, { + return await UpdateInfo.updateAsync({ _id: updateId }, { $set: { viewed: true } diff --git a/imports/api/userConfig.js b/imports/api/userConfig.js index a1d0614..ac6ab2e 100644 --- a/imports/api/userConfig.js +++ b/imports/api/userConfig.js @@ -16,27 +16,27 @@ UserConfig.allow({ }); Meteor.methods({ - 'add.darkModePref' (pref) { + async 'add.darkModePref' (pref) { check(pref, String); if (!this.userId) { 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, darkMode: pref, dateAdded: Date() }); }, - 'update.darkModePref' (pref) { + async 'update.darkModePref' (pref) { check(pref, String); if (!this.userId) { 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: { darkMode: pref, dateUpdate: Date() diff --git a/imports/api/userConfigOptions.js b/imports/api/userConfigOptions.js index c6290a2..09c9207 100644 --- a/imports/api/userConfigOptions.js +++ b/imports/api/userConfigOptions.js @@ -12,10 +12,10 @@ UserConfigOptions.allow({ }); Meteor.methods({ - 'change.userPass' (usersId, password) { + async 'change.userPass' (usersId, password) { check(usersId, String); check(password, String); - return Accounts.setPasswordAsync(usersId, password); + return await Accounts.setPasswordAsync(usersId, password); }, }); \ No newline at end of file diff --git a/imports/api/userLast.js b/imports/api/userLast.js index dbeb078..33e156b 100644 --- a/imports/api/userLast.js +++ b/imports/api/userLast.js @@ -12,7 +12,7 @@ UserLast.allow({ }); Meteor.methods({ - 'add.userLast' (view, viewId) { + async 'add.userLast' (view, viewId) { check(view, String); check(viewId, String); @@ -22,36 +22,33 @@ Meteor.methods({ // 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 - const getUserLast = async() => { - let userListInfo = await UserLast.findOneAsync({ userId: this.userId, view: view }); - if (!userListInfo) { - console.log("Adding new user last item."); - return UserLast.insertAsync({ - userId: this.userId, - view: view, - viewId: viewId, - dateAdded: Date(), - }); + let userListInfo = await UserLast.findOneAsync({ userId: this.userId, view: view }); + if (!userListInfo) { + console.log("Adding new user last item."); + return await UserLast.insertAsync({ + userId: this.userId, + view: view, + viewId: viewId, + dateAdded: Date(), + }); + } else { + console.log("Editing existing user last itme."); + // entry exists, call the edit function instead + let result = await Meteor.callAsync('edit.userLast', view, viewId); + if (!result) { + try { + console.log("Issue editing existing entry in userLast. Check the logs."); + } catch(error) { + console.log(" ERROR adding userLast item: " + error); + console.log(error.message); + console.log(error.stack); + } } else { - console.log("Editing existing user last itme."); - // entry exists, call the edit function instead - let result = await Meteor.callAsync('edit.userLast', view, viewId); - if (!result) { - try { - console.log("Issue editing existing entry in userLast. Check the logs."); - } catch(error) { - console.log(" ERROR adding userLast item: " + error); - console.log(error.message); - console.log(error.stack); - } - } else { - return true; - } + return true; } } - return getUserLast(); }, - 'edit.userLast' (view, viewId) { + async 'edit.userLast' (view, viewId) { check(view, String); check(viewId, String); @@ -60,7 +57,7 @@ Meteor.methods({ } console.log("Edit in progress."); - return UserLast.updateAsync({ view: view, userId: this.userId }, { + return await UserLast.updateAsync({ view: view, userId: this.userId }, { $set: { viewId: viewId, dateLastUpdate: Date(), diff --git a/server/methods.js b/server/methods.js index 742a93e..d634eed 100644 --- a/server/methods.js +++ b/server/methods.js @@ -6,66 +6,63 @@ import { SysConfig } from '../imports/api/systemConfig'; import { Roles } from 'meteor/roles'; Meteor.methods({ - 'addToRole' (role) { - const getUserInfo = async() => { - try { - let countOfUsers = await Meteor.users.find().countAsync(); - const user = await Meteor.userAsync(); - if (user) { - let userId = user._id; - if (countOfUsers > 1) { - Roles.addUsersToRolesAsync(userId, role); - const result = await Meteor.callAsync('add.darkModePref', "light"); - if (!result) { - console.log(" ERROR: can't set user dark mode preference: " + err); - } else { - // console.log(" SUCCESSFULLY set user dark mode preference."); - } - } else if (countOfUsers == 1) { - Roles.addUsersToRolesAsync(userId, "systemadmin"); - const result = await Meteor.callAsync('add.darkModePref', "light"); - if (!result) { - console.log(" ERROR: can't set user dark mode preference: " + err); - } else { - console.log(" SUCCESSFULLY set user dark mode preference."); - } + async 'addToRole' (role) { + try { + let countOfUsers = await Meteor.users.find().countAsync(); + const user = await Meteor.userAsync(); + if (user) { + let userId = user._id; + if (countOfUsers > 1) { + await Roles.addUsersToRolesAsync(userId, role); + const result = await Meteor.callAsync('add.darkModePref', "light"); + if (!result) { + console.log(" ERROR: can't set user dark mode preference: " + err); } else { - console.log("The count of users didn't seem to work when adding a new user."); + // console.log(" SUCCESSFULLY set user dark mode preference."); + } + } else if (countOfUsers == 1) { + await Roles.addUsersToRolesAsync(userId, "systemadmin"); + const result = await Meteor.callAsync('add.darkModePref', "light"); + if (!result) { + console.log(" ERROR: can't set user dark mode preference: " + err); + } else { + console.log(" SUCCESSFULLY set user dark mode preference."); } } else { - console.log(" ---- No user info found.") + console.log("The count of users didn't seem to work when adding a new user."); } - } catch(error) { - console.log(" ERROR getting user info on server: " + error); + } else { + console.log(" ---- No user info found.") } + } catch(error) { + console.log(" ERROR getting user info on server: " + error); } - getUserInfo(); }, - 'edit.userPass' (userId, newPassword) { + async 'edit.userPass' (userId, newPassword) { check(userId, 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); - 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(email, String); - return Meteor.users.updateAsync({ _id: userId }, { + return await Meteor.users.updateAsync({ _id: userId }, { $set: { 'emails.0.address': email, } }); }, - 'edit.userRole' (userId, role) { + async 'edit.userRole' (userId, role) { check(userId, String); check(role, String); - return Roles.setUserRolesAsync(userId, role); + return await Roles.setUserRolesAsync(userId, role); }, });