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) => {
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);

View file

@ -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 });
}
});

View file

@ -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 });
},
});

View file

@ -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(),

View file

@ -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],

View file

@ -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,
}

View file

@ -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(),

View file

@ -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 });
}
});

View file

@ -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 });
}
});

View file

@ -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 });
}
});

View file

@ -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 });
},
});

View file

@ -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 });
},
});

View file

@ -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,
}

View file

@ -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
}

View file

@ -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()

View file

@ -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);
},
});

View file

@ -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(),

View file

@ -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);
},
});