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
63
imports/api/shopList.js
Normal file
63
imports/api/shopList.js
Normal 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!");
|
||||
}
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue