In Node js, i am using express validator to validate the request body of an API.
I have one file validators.js
where I define validators for an API request.
I want to validate inviteesArray
which needs to be in below format:
//expected
[
{"userId" :"07aeb7ff-bf11-4a64-b842-a6fe1aa0a7f6"},
{"userId" :"7b89059a-3915-4d1d-b55c-077260f07021"}
];
my validator:
body('inviteesArray','inviteesArray is required!').if((value, { req }) => req.body.isInvited !== "false").isArray().notEmpty(),
request in postman, which gives validation error, what am I doing wrong?
**UPDATE**
when i change my validator with removing the if condition it works.
body('inviteesArray','inviteesArray is required!').if((value, { req }) => console.log(value)).isArray().notEmpty(),
You hove to add object keys inside braces to pass as an array of object