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

View file

@ -12,8 +12,9 @@ Lists.allow({
});
Meteor.methods({
'add.list' (listName) {
'add.list' (listName, isShared) {
check(listName, String);
check(isShared, Boolean);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add lists. Make sure you are logged in with valid user credentials.');
@ -21,13 +22,15 @@ Meteor.methods({
return Lists.insert({
listName: listName,
listShared: isShared,
listOwner: this.userId,
listComplete: false,
});
},
'edit.list' (listId, listName) {
'edit.list' (listId, listName, isShared) {
check(listId, String);
check(listName, String);
check(isShared, Boolean);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to edit lists. Make sure you are logged in with valid user credentials.');
@ -36,6 +39,7 @@ Meteor.methods({
return Lists.update({ _id: listId }, {
$set: {
listName: listName,
listShared: isShared,
}
});
},
@ -62,18 +66,11 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to mark lists complete. Make sure you are logged in with valid user credentials.');
}
let listInfo = Lists.findOne({ _id: listId });
let myId = this.userId;
if (myId == listInfo.listOwner) {
return Lists.update({ _id: listId }, {
$set: {
listComplete: true,
completedOn: new Date()
}
});
} else {
console.log("User not allowed to mark lists complete. Not a member of the list!");
return("Not Allowed!");
}
return Lists.update({ _id: listId }, {
$set: {
listComplete: true,
completedOn: new Date()
}
});;
}
});

View file

@ -41,7 +41,7 @@ Meteor.methods({
throw new Meteor.Error('You are not allowed to edit products. Make sure you are logged in with valid user credentials.');
}
return Products.update({ _id: itemId }, {
return Products.update({ _id: prodId }, {
$set: {
prodName: prodName,
prodCategory: prodCategory,
@ -59,7 +59,7 @@ Meteor.methods({
let prodInfo = Products.findOne({ _id: prodId });
let myId = this.userId;
if (myId == prodInfo.owner) {
if (myId == prodInfo.prodOwner) {
return Products.remove({ _id: prodId });
} else {
console.log("User not allowed to delete this product. Not the owner!");

View file

@ -12,26 +12,21 @@ Stores.allow({
});
Meteor.methods({
'add.store' (storeName, storeType) {
'add.store' (storeName) {
check(storeName, String);
check(storeType, 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.');
}
console.log(" ---- userid: " + Meteor.user()._id);
return Stores.insert({
storeName: storeName,
storeType: storeType,
owner: Meteor.user()._id,
owner: this.userId,
});
},
'edit.store' (storeId, storeName, storeType) {
'edit.store' (storeId, storeName) {
check(storeId, String);
check(storeName, String);
check(storeType, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to edit stores. Make sure you are logged in with valid user credentials.');
@ -40,7 +35,6 @@ Meteor.methods({
return Stores.update({ _id: storeId }, {
$set: {
storeName: storeName,
storeType: storeType,
}
});
},