mixin-promise
Get a promise from your method
install
meteor add cesarve:mixin-promise
Usage
1//example method creation 2import {ValidatedMethod} from 'meteor/mdg:validated-method' 3import promiseMixin from 'cesarve:mixin-promise' 4import schemaMixin from 'cesarve:mixin-schema' 5 6export const methodUpdate = new ValidatedMethod({ 7 name: 'methodUpdate', 8 mixins: [schemaMixin, promiseMixin], 9 schema: new SimpleSchema({ //see cesarve:mixin-schema 10 _id: String, 11 name: String, 12 surname: String, 13 }), // 14 run({_id,...doc}) { 15 if (!Roles.userIsInRole(this.userId,['admin'])){ 16 throw new Meteor.Error(403, 'Access denied') 17 } 18 return MyCollection.update(_id, {$set: {...doc, updatedAt: new Date()} }) 19 20 } 21})
1//example method called as promise 2import {methodUpdate} from './path/to/method' 3 4 methodUpdate.promise({_id: 'xxxx', name:'xxxx', surname:'xxxxxx'}) 5 .then(()=>console.log('success')) 6 .catch((err)=>console.error(err)) 7