mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 00:08:49 +00:00
Updates for async and await - still
This commit is contained in:
parent
febb36d75f
commit
706c5dc3ef
18 changed files with 220 additions and 233 deletions
|
|
@ -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 });
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue