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 }); }, });