Certainly yes, I've recently made an improvement to it in my personal codes. The validator takes schema as a param. I found it cleaner and I'd update the article ASAP. Below is what it looks like:
const{body,validationResult}=require('express-validator');constvalidate=(schemas)=>{returnasync(req,res,next)=>{awaitPromise.all(schemas.map((schema)=>schema.run(req)));constresult=validationResult(req);if(result.isEmpty()){returnnext();}consterrors=result.array();returnres.send(errors)};}constexampleSchema=[body('foo','The foo field is required').notEmpty(),...];router.post('/foos',validate(exampleSchema),fooHandler);
seems oneOf is middleware not a ValidationChain[]. I'm handling it manually using a custom rule because that allows me to continue using similar "validate" middleware, although, what else are we missing by having this convenience "validate" wrapper .
Great writeup!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Certainly yes, I've recently made an improvement to it in my personal codes. The validator takes schema as a param. I found it cleaner and I'd update the article ASAP. Below is what it looks like:
This is just awesome! Thank you so much!
Anytime!
How would you implement mutually exclusive properties like google maps geocoding?
can be either: address or latlng but not both
github.com/express-validator/expre...
seems oneOf is middleware not a ValidationChain[]. I'm handling it manually using a custom rule because that allows me to continue using similar "validate" middleware, although, what else are we missing by having this convenience "validate" wrapper .
Great writeup!