mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 00:08:49 +00:00
My big initial commit to this repo and project.
This commit is contained in:
parent
750811a81f
commit
8636f8cf9b
2433 changed files with 199488 additions and 1042 deletions
69
imports/api/products.js
Normal file
69
imports/api/products.js
Normal 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!");
|
||||
}
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue