Skip to content

Commit

Permalink
Merge pull request #656 from PierreBrisorgueil/featExposeGetResultFro…
Browse files Browse the repository at this point in the history
…mJoi

feat(lib): expose Joi function from middleware, for dynamic schema ✨
  • Loading branch information
PierreBrisorgueil authored Mar 6, 2020
2 parents f5ad1df + e6fac31 commit 8c16f9a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/middlewares/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const responses = require(path.resolve('./lib/helpers/responses'));
/**
* get Joi result
*/
const getResultFromJoi = (body, schema, options) => Joi.validate(body, schema, options, (err, data) => {
module.exports.getResultFromJoi = (body, schema, options) => Joi.validate(body, schema, options, (err, data) => {
if (err) {
const output = {
status: 'failed',
Expand Down Expand Up @@ -41,7 +41,7 @@ module.exports.isValid = (schema) => (req, res, next) => {
options.noDefaults = true;
}
// Validate req.body using the schema and validation options
const result = getResultFromJoi(req.body, schema, options);
const result = this.getResultFromJoi(req.body, schema, options);
// if error
if (result && result.error) {
if (result.error.original && (result.error.original.password || result.error.original.firstname)) result.error.original = _.pick(result.error.original, config.whitelists.users.default);
Expand Down

0 comments on commit 8c16f9a

Please sign in to comment.