mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-26 15:58:50 +00:00
50 lines
No EOL
1.4 KiB
JavaScript
50 lines
No EOL
1.4 KiB
JavaScript
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({
|
|
async '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 await ShopLists.insert({
|
|
shopName: shopName,
|
|
shopOwner: this.userId,
|
|
});
|
|
},
|
|
async '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 await ShopLists.update({ _id: shopId }, {
|
|
$set: {
|
|
shopName: shopName,
|
|
}
|
|
});
|
|
},
|
|
async '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.');
|
|
}
|
|
|
|
return await ShopLists.remove({ _id: shopId });
|
|
},
|
|
}); |