Created
June 5, 2018 15:35
-
-
Save sbalay/cccf80145391c31d0c5bbe91058a1175 to your computer and use it in GitHub Desktop.
Express validator example
This file contains hidden or 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
const { checkSchema } = require('express-validator/check'); | |
exports.validateCalculate = [ | |
checkSchema({ | |
product: { | |
in: ['query'], | |
errorMessage: 'product must be an integer', | |
exists: true, | |
isInt: { options: { min: 0 } }, | |
toInt: true | |
}, | |
unit_price: { | |
in: ['query'], | |
errorMessage: 'unit_price must be a positive float', | |
exists: true, | |
isFloat: { options: { min: 0 } }, | |
toFloat: true | |
}, | |
total_cost: { | |
in: ['query'], | |
errorMessage: 'total_cost must be a positive float', | |
exists: true, | |
isFloat: { options: { min: 0 } }, | |
toFloat: true | |
}, | |
dispatched_at: { | |
in: ['query'], | |
errorMessage: 'dispatched_at must be a date time', | |
exists: true, | |
custom: { | |
options: value => { | |
return !!value && !!Date.parse(value); | |
} | |
}, | |
toDate: true | |
} | |
}) | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment