init
This commit is contained in:
21
lib/factory/validate.js
Normal file
21
lib/factory/validate.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const Joi = require('joi')
|
||||
|
||||
module.exports = function (schema, props) {
|
||||
//
|
||||
// Validate and remove unknown keys
|
||||
//
|
||||
var {error, value} = Joi.validate(props, schema, {
|
||||
presence: 'required',
|
||||
stripUnknown: true
|
||||
})
|
||||
//
|
||||
// Throw validation errors
|
||||
//
|
||||
if (error) {
|
||||
throw error
|
||||
}
|
||||
//
|
||||
// Return the value
|
||||
//
|
||||
return value
|
||||
}
|
||||
Reference in New Issue
Block a user