Created
September 3, 2018 16:22
-
-
Save xtrinch/361f4487c591a81f7cd7f5a49c1f7849 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var validate = require('sails-hook-validation-ev/lib/validate') | |
module.exports = { | |
create: async function(req, res) { | |
validate(req, (req) => { | |
req.check('title') | |
.exists() | |
.isLength({ min: 1 }).withMessage('must be at least 5 chars long'); | |
req.check('description').exists(); | |
}) | |
const errors = await req.getValidationResult(); | |
if (!errors.isEmpty()) { | |
return res.status(400).json({ errors: errors.array() }); | |
} | |
return res.ok() | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment