const { validationResult } = require('express-validator')

// Collect express-validator results and 400 on failure.
function validate(req, res, next) {
  const errors = validationResult(req)
  if (!errors.isEmpty()) {
    return res.status(400).json({ message: 'Validation failed', errors: errors.array() })
  }
  next()
}

module.exports = validate
