mixin-promise
Use Simple Schema direct in your method
install
meteor add cesarve:mixin-schema
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//to access your schema you can use: 5 6const schema=methodUpdate.schema 7 8 methodUpdate.call({_id: 'xxxx', name:'xxxx', surname:'xxxxxx'},(err,res)=>{ 9 if (err) return console.error(err) 10 console.log('success') 11 }) 12