Created
August 8, 2012 08:59
-
-
Save Radagaisus/3293617 to your computer and use it in GitHub Desktop.
Express Validator Suger
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
| # Implementation | |
| pre = (fn, error_handler, great) -> | |
| fn() | |
| errors = req.validationErrors() | |
| if errors | |
| v(errors) for k,v of error_handler | |
| else | |
| v() for k,v of great | |
| # Result | |
| pre -> | |
| req.assert('postparam', 'Invalid postparam').notEmpty().isInt() | |
| req.assert('getparam', 'Invalid getparam').isInt() | |
| req.assert('urlparam', 'Invalid urlparam').isAlpha() | |
| , error: (errors) -> | |
| res.json errors | |
| , great: -> | |
| # Continue as usual |
Author
Radagaisus
commented
Aug 8, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment