Many chcanges, but version 0.1.0 is ready to be cut.

This commit is contained in:
Brian McGonagill 2022-08-23 13:41:21 -05:00
parent 42643a37f5
commit 6e37ae8c74
46 changed files with 1038 additions and 273 deletions

View file

@ -14,35 +14,53 @@ ListItems.allow({
});
Meteor.methods({
'add.listItem' (itemName, prodId, itemQty, shopListId) {
'add.listItem' (itemName, listId) {
check(itemName, String);
check(prodId, String);
check(itemQty, String);
check(shopListId, String);
check(listId, 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.');
}
// look up the item from the Products collection
let prodInfo = Products.findOne({ _id: prodId });
let prodInfo = Products.findOne({ prodName: itemName });
if (typeof prodInfo == "undefined") {
Meteor.call("add.product", itemName, "", "", "", function(err, result) {
if (err) {
console.log(" ERROR adding item to products: " + err);
} else {
console.log(" SUCCESS adding item to Products.");
return ListItems.insert({
itemName: itemName,
listId: listId,
prodId: result,
addedBy: this.userId,
itemCategory: "",
itemStore: "",
itemLocation: "",
itemOrdered: false,
itemReceived: false,
dateAddedToList: new Date(),
});
}
});
} else {
return ListItems.insert({
itemName: itemName,
listId: listId,
prodId: prodInfo._id,
addedBy: this.userId,
itemCategory: prodInfo.prodCategory,
itemStore: prodInfo.prodStore,
itemLocation: prodInfo.prodLocation,
itemOrdered: false,
itemReceived: false,
dateAddedToList: new Date(),
});
}
// look up the shopList by shopListId
let shopListInfo = ShopLists.findOne({ _id: shopListId });
return ListItems.insert({
itemName: itemName,
prodId: prodId,
itemQty: itemQty,
itemOwner: shopListInfo.ownerId,
addedBy: this.userId,
itemCategory: prodInfo.prodCategory,
itemStore: prodInfo.prodStore,
itemLocation: prodInfo.prodLocation,
itemOrdered: false,
itemReceived: false,
dateAddedToList: new Date(),
});
},
'setOrdered.listItem' (itemId) {
check(itemId, String);
@ -109,33 +127,17 @@ Meteor.methods({
// set all items that are not already listed as received to received on this list
},
'edit.listItem' (itemId, itemName, prodId, itemQty, shopListId) {
'edit.listItem' (itemId, itemName) {
check(itemId, String);
check(itemName, String);
check(prodId, String);
check(itemQty, String);
check(shopListId, 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.');
}
// look up the item from the Products collection
let prodInfo = Products.findOne({ _id: prodId });
// look up the shopList by shopListId
let shopListInfo = ShopLists.findOne({ _id: shopListId });
return ListItems.update({ _id: itemId }, {
$set: {
itemName: itemName,
prodId: prodId,
itemQty: itemQty,
itemOwner: shopListInfo.ownerId,
editedBy: this.userId,
itemCategory: prodInfo.prodCategory,
itemStore: prodInfo.prodStore,
itemLocation: prodInfo.prodLocation,
}
});
},
@ -146,13 +148,6 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to delete list items. Make sure you are logged in with valid user credentials.');
}
let itemInfo = ListItems.findOne({ _id: itemId });
let myId = this.userId;
if (myId == itemInfo.owner) {
return ListItems.remove({ _id: itemId });
} else {
console.log("User not allowed to delete this list item. Not the owner!");
return("Not Allowed!");
}
return ListItems.remove({ _id: itemId });
}
});