My big initial commit to this repo and project.

This commit is contained in:
Brian McGonagill 2022-08-05 16:55:56 -05:00
parent 750811a81f
commit 8636f8cf9b
2433 changed files with 199488 additions and 1042 deletions

57
imports/api/category.js Normal file
View file

@ -0,0 +1,57 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const Categories = new Mongo.Collection('categories');
Categories.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
'add.category' (name) {
check(name, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add categories. Make sure you are logged in with valid user credentials.');
}
return Categories.insert({
categoryName: name,
categroyOwner: this.userid,
});
},
'edit.category' (categoryId, categoryName,) {
check(categoryId, String);
check(categoryName, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to edit categories. Make sure you are logged in with valid user credentials.');
}
return Categories.update({ _id: categoryId }, {
$set: {
categoryName: categoryName,
}
});
},
'delete.category' (categoryId) {
check(categoryId, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete categories. Make sure you are logged in with valid user credentials.');
}
let categoryInfo = Categories.findOne({ _id: categoryId });
let myId = this.userId;
if (myId == categoryInfo.owner) {
return Categories.remove({ _id: categoryId });
} else {
console.log("User not allowed to delete this Category. Not the owner!");
return("Not Allowed!");
}
},
});

158
imports/api/listItems.js Normal file
View file

@ -0,0 +1,158 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
import { Products } from './products';
import { ShopLists } from './shopList';
export const ListItems = new Mongo.Collection('listitems');
ListItems.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
'add.listItem' (itemName, prodId, itemQty, shopListId) {
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.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);
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.update({ _id: itemId }, {
$set: {
itemOrdered: true,
dateOrdered: new Date(),
}
});
},
'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) {
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.update({ _id: itemId }, {
$set: {
itemOrdered: false,
dateUnOrdered: new Date(),
}
});
},
'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.update({ _id: itemId }, {
$set: {
itemReceived: true,
dateReceived: new Date(),
}
});
},
'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.update({ _id: itemId }, {
$set: {
itemReceived: false,
dateNotReceived: new Date(),
}
});
},
'setAllReceived.listItem' () {
// set all items that are not already listed as received to received on this list
},
'edit.listItem' (itemId, itemName, prodId, itemQty, shopListId) {
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,
}
});
},
'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.');
}
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!");
}
}
});

57
imports/api/lists.js Normal file
View file

@ -0,0 +1,57 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const Lists = new Mongo.Collection('lists');
Lists.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
'add.list' (listName) {
check(listName, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add lists. Make sure you are logged in with valid user credentials.');
}
return Lists.insert({
listName: listName,
listOwner: this.userId;
});
},
'edit.list' (listId, listName) {
check(listId, String);
check(listName, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to edit lists. Make sure you are logged in with valid user credentials.');
}
return Lists.update({ _id: listId }, {
$set: {
listName: listName,
}
});
},
'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.');
}
let listInfo = Lists.findOne({ _id: listId });
let myId = this.userId;
if (myId == listInfo.owner) {
return Lists.remove({ _id: listId });
} else {
console.log("User not allowed to delete this list. Not the owner!");
return("Not Allowed!");
}
}
});

61
imports/api/location.js Normal file
View file

@ -0,0 +1,61 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const Locations = new Mongo.Collection('locations');
Locations.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
'add.location' (name, type) {
check(name, String);
check(type, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add locations. Make sure you are logged in with valid user credentials.');
}
return Locations.insert({
locationName: name,
locationType: type,
owner: this.userid,
});
},
'edit.location' (locationId, locationName, locationType) {
check(locationId, String);
check(locationName, String);
check(locationType, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to edit locations. Make sure you are logged in with valid user credentials.');
}
return Locations.update({ _id: locationId }, {
$set: {
locationName: locationName,
locationType: locationType,
}
});
},
'delete.location' (locationId) {
check(locationId, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete locations. Make sure you are logged in with valid user credentials.');
}
let locationInfo = Locations.findOne({ _id: locationId });
let myId = this.userId;
if (myId == locationInfo.owner) {
return Locations.remove({ _id: locationId });
} else {
console.log("User not allowed to delete this location. Not the owner!");
return("Not Allowed!");
}
},
});

View file

@ -1,42 +0,0 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const Messages = new Mongo.Collection('messages');
Messages.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
'add.message' (entityId, messageText, imageData, intendedRecipient, isGroupRecipient) {
check(entityId, String);
check(messageText, String);
check(imageData, String);
check(intendedRecipient, String);
check(isGroupRecipient, Boolean);
if (!this.userId) {
throw new Meteor.Error('User is not allowed to add new messages in the system, make sure you are logged in.');
}
// need to get the userId and role, and ensure the message is sent properly to the appropriate person / people
},
'delete.message' (messageId) {
check(messageId, String);
if (!this.userId) {
throw new Meteor.Error('User is not allowed to add new messages in the system, make sure you are logged in.');
}
return Messages.update({ _id: messageId }, {
$set: {
isDeleted: true,
}
});
},
});

69
imports/api/products.js Normal file
View file

@ -0,0 +1,69 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const Products = new Mongo.Collection('products');
Products.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
'add.product' (prodName, prodCategory, prodStore, prodLocation) {
check(prodName, String);
check(prodCategory, String);
check(prodStore, String);
check(prodLocation, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add products. Make sure you are logged in with valid user credentials.');
}
return Products.insert({
prodName: prodName,
prodOwner: this.userId,
prodCategory: prodCategory,
prodStore: prodStore,
prodLocation: prodLocation,
});
},
'edit.product' (prodId, prodName, prodCategory, prodStore, prodLocation) {
check(prodId, String);
check(prodName, String);
check(prodCategory, String);
check(prodStore, String);
check(prodLocation, String);
if (!this.userId) {
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 }, {
$set: {
prodName: prodName,
prodCategory: prodCategory,
prodStore: prodStore,
prodLocation: prodLocation,
}
});
},
'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.');
}
let prodInfo = Products.findOne({ _id: prodId });
let myId = this.userId;
if (myId == prodInfo.owner) {
return Products.remove({ _id: prodId });
} else {
console.log("User not allowed to delete this product. Not the owner!");
return("Not Allowed!");
}
}
});

View file

@ -1,79 +0,0 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const ServiceEntities = new Mongo.Collection('serviceEntities');
ServiceEntities.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
'add.serviceEntity' (name, code, address, city, state, zip, phone, email, type) {
check(name, String);
check(code, String);
check(address, String);
check(city, String);
check(state, String);
check(zip, String);
check(phone, String);
check(email, String);
check(type, String);
if (!this.userId) {
throw new Meteor.Error('User is not allowed to add new Service Entities, make sure you are logged in.');
}
return ServiceEntities.insert({
name: name,
code: code,
address: address,
city: city,
state: state,
zip: zip,
phone: phone,
email: email,
type: type,
isActive: true,
addedOn: new Date(),
addedBy: Meteor.user().emails[0].address,
});
},
'edit.serviceEntities' (entityId, name, code, address, city, state, zip, phone, email, type, isActive) {
check(entityId, String);
check(name, String);
check(code, String);
check(address, String);
check(city, String);
check(state, String);
check(zip, String);
check(phone, String);
check(email, String);
check(type, String);
check(isActive, Boolean);
if (!this.userId) {
throw new Meteor.Error('User is not allowed to add new Service Entities, make sure you are logged in.');
}
return ServiceEntities.update({ _id: entityId }, {
$set: {
name: name,
code: code,
address: address,
city: city,
state: state,
zip: zip,
phone: phone,
email: email,
type: type,
isActive: isActive,
updatedOn: new Date(),
updatedBy: Meteor.user().emails[0].address,
}
});
},
});

63
imports/api/shopList.js Normal file
View file

@ -0,0 +1,63 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const ShopLists = new Mongo.Collection('shoplists');
ShopLists.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
'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({
shopName: shopName,
shopOwner: this.userId,
});
},
'add.shopListUsers' (userIds) {
},
'edit.shopList' (shopId, shopName) {
check(shopId, String);
check(shopName, String);
if (!this.userId) {
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 }, {
$set: {
shopName: shopName,
}
});
},
'edit.shopListUsers' (shopId, userIds) {
},
'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.');
}
let shopInfo = ShopLists.findOne({ _id: shopId });
let myId = this.userId;
if (myId == shopInfo.owner) {
return ShopLists.remove({ _id: shopId });
} else {
console.log("User not allowed to delete this shopping list. Not the owner!");
return("Not Allowed!");
}
},
});

61
imports/api/stores.js Normal file
View file

@ -0,0 +1,61 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const Stores = new Mongo.Collection('stores');
Stores.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
'add.store' (storeName, storeType) {
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.');
}
return Stores.insert({
storeName: storeName,
storeType: storeType,
owner: this.userid,
});
},
'edit.store' (storeId, storeName, storeType) {
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.');
}
return Stores.update({ _id: storeId }, {
$set: {
storeName: storeName,
storeType: storeType,
}
});
},
'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.');
}
let storeInfo = Stores.findOne({ _id: storeId });
let myId = this.userId;
if (myId == storeInfo.owner) {
return Stores.remove({ _id: storeId });
} else {
console.log("User not allowed to delete this store. Not the owner!");
return("Not Allowed!");
}
},
});