Skip to content

Instantly share code, notes, and snippets.

@solanoize
Created May 14, 2024 14:54
Show Gist options
  • Select an option

  • Save solanoize/4b5f3ae36d4cc2d6782649802efe0930 to your computer and use it in GitHub Desktop.

Select an option

Save solanoize/4b5f3ae36d4cc2d6782649802efe0930 to your computer and use it in GitHub Desktop.
const Validate = (validations) => {
return async (err, req, res, next) => {
for (let validation of validations) {
await validation.run(req);
// if (result.errors.length) break;
}
const errors = validationResult(req);
const errs = _.chain(errors.errors).groupBy("path").value()
console.log("test", errors.isEmpty())
if (errors.isEmpty()) {
req.cleanedData = matchedData(req);
return next();
}
res.status(400).json(errs);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment