Answers for "Joi validation in a Mongoose model"

0

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()
  }
}
Posted by: Guest on June-24-2021

Browse Popular Code Answers by Language