Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lib): expose Joi function from middleware, for dynamic schema ✨ #656

Merged
merged 1 commit into from
Mar 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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