function middleware(
  req,
  {locals},
  next,
  schema = {},
  options = {},
  {
    readFrom = readWriteDefaults[req.method],
    writeTo = readWriteDefaults[req.method]
  } = {}
) {
  /* eslint-disable-next-line no-param-reassign */
  options = {
    stripUnknown: true,
    ...options
  };

  const {error, value} = validate(req[readFrom], schema, options);

  if (error !== null) {
    return next(badRequest(error.message, error.details));
  }

  // Set the validated and optionally cast values
  locals[writeTo] = {...locals[writeTo], ...value};

  next();
}
/**
 * Express middleware to validate request query parameters, bodies, and headers.
 * @private
 * @param {Object} req
 * @param {Object} res
 * @param {Function} next
 * @param {Object} [schema={}] A Joi schema object.
 * @param {Object} [options={stripUnknown: true}] A Joi validation options
 *  object.
 * @param {Object} [param6]
 * @param {String} [param6.readFrom=query or body] The path to read from
 *  the request object (if undefined it will default to either the query or body
 *  of the request object depending on the request method).
 * @param {String} [param6.writeTo=query or body] The path to set the
 *  validated/cast values on the response locals object (if undefined it will
 *  default to either the query or body of the request object depending on the
 *  request method).
 * @return {Promise}
 */
Express middleware to validate request query parameters, bodies, and headers.
Express middleware to validate request query parameters bodies and headers .
function middleware(
  req,
  {locals},
  next,
  schema = {},
  options = {},
  {
    readFrom = readWriteDefaults[req.method],
    writeTo = readWriteDefaults[req.method]
  } = {}
) {
  options = {
    stripUnknown: true,
    ...options
  };
  const {error, value} = validate(req[readFrom], schema, options);
  if (error !== null) {
    return next(badRequest(error.message, error.details));
  }
  locals[writeTo] = {...locals[writeTo], ...value};
  next();
}
function middleware ( req , { locals } , next , schema = { } , options = { } , { readFrom = readWriteDefaults [ req . method ] , writeTo = readWriteDefaults [ req . method ] } = { } ) { options = { stripUnknown : true , ... options } ; const { error , value } = validate ( req [ readFrom ] , schema , options ) ; if ( error !== null ) { return next ( badRequest ( error . message , error . details ) ) ; } locals [ writeTo ] = { ... locals [ writeTo ] , ... value } ; next ( ) ; }
Express middleware to validate request query parameters, bodies, and headers.
Express middleware to validate request query parameters bodies and headers .
/* eslint-disable-next-line no-param-reassign */ // Set the validated and optionally cast values