seneca-merge-validate
v1.0.7
Published
SenecaJS Merge Validate
Downloads
2
Maintainers
Readme
seneca-merge-validate
About
SenecaJS Merge Validate is a abstraction package made to validate/formate a message payload data, the same is also used in seneca-sequelize package
Example
function Plugin () {
const seneca = this
const Joi = require('joi')
const SenecaMergeValidate = require('seneca-merge-validate')
const senecaMergeValidate = SenecaMergeValidate(seneca)
const PICK_FIELDS = [
'field'
]
seneca.add({ role: 'plugin', cmd: 'create' }, cmd_create)
function cmd_create (args, done) {
senecaMergeValidate.validate({
args,
pick: PICK_FIELDS,
schema: getValidateSchema(),
options: { abortEarly: false }
})
.then(params => create(params))
.then(result => done(null, result))
.catch(err => done(null, err))
}
function getValidateSchema () {
return {
field: Joi.any()
.required()
}
}
function createService (params) {
return new Promise((resolve, reject) => {
return reject({ status: false, message: 'Error' })
return resolve({ status: true, result: {} })
})
}
}