Skip to content

Instantly share code, notes, and snippets.

@xtrinch
Created September 3, 2018 16:22
Show Gist options
  • Save xtrinch/361f4487c591a81f7cd7f5a49c1f7849 to your computer and use it in GitHub Desktop.
Save xtrinch/361f4487c591a81f7cd7f5a49c1f7849 to your computer and use it in GitHub Desktop.
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