I am trying to send an array of the object as a form-data using postman. Then validate the data using express-validate I created a function that will handle the validation process of my body.
validate.js
import { check, body } from "express-validator";
import { validationResult } from "express-validator";
export const addEvent = () => {
return [
check("name", "Name is required").notEmpty(),
check("pricing")
.isArray()
.notEmpty(),
check("pricing.*.ticketType")
.notEmpty()
.withMessage("Price type is required"),
check("pricing.*.price")
.notEmpty()
.withMessage("Price type is required"),
(req, res, next) => {
let errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({
message: "Invalid parameters",
stack: errors.array({ onlyFirstError: true }),
});
} else {
next()
}
}
]
}
And this is how i test it using postman
but when I tested it out it returns an error
"message": "Cannot convert object to primitive value"