Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Joi validation in a Mongoose model

// validateMiddleware
module.exports = (validator) => {
  return (req, res, next) => {
    const { error } = validator(req.body)
    console.log('error: ', error)
    if (error) {
      return res.status(400).send(error.details[0].message)
    }
    next()
  }
}
Source by gist.github.com #
 
PREVIOUS NEXT
Tagged: #Joi #validation #Mongoose #model
ADD COMMENT
Topic
Name
6+6 =