Skip to content

Commit

Permalink
Chore(validate): add a validate middleware
Browse files Browse the repository at this point in the history
this will allow the usage of one validate function to be used
across the project.
  • Loading branch information
MuhannedNoman committed Sep 17, 2020
1 parent c8bf4b6 commit 92da5cd
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions middleware/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = (validator) => {
return (req, res, next) => {
const { error } = validator(req.body);
if (error) return res.status(400).send(error.details[0].message);
next();
};
};

0 comments on commit 92da5cd

Please sign in to comment.