get_my/imports/api/products.js
Brian McGonagill 3f6618d906 Updaated Products to have multiple associated stores.
- Products will be updated on first start of server to make sure the store attribute is set as an Array of values.
- You can edit Products to add more associated stores
- Products will list all associated stores on the product table view
- Cut down method calls to single event trigger for adding / editing products info
2024-08-13 10:48:27 -05:00

54 lines
1.5 KiB
JavaScript

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, prodStore) {
check(prodName, String);
check(prodStore, [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,
prodStore: prodStore,
});
},
'edit.product' (prodId, prodName, prodStore) {
check(prodId, String);
check(prodName, String);
check(prodStore, [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: prodId }, {
$set: {
prodName: prodName,
prodStore: prodStore,
}
});
},
'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.remove({ _id: prodId });
}
});