I have a route that POSTs new products. In it I am handling express validator and in this case I validate that the category and the provider are not empty but it never throws and stops the check message and goes to the Mongoose error message. This is the code:
router.post('/', upload.array('pictures', 3),
[
jwtValidation,
role('SUPER_ROLE','WAREHOUSE_ROLE'),
check('category', 'La Categoría del producto es obligatoria').not().isEmpty(),
check('category', 'No es un Id de Categoría Válido').isMongoId(),
check('provider', 'El Proveedor del producto es obligatorio').not().isEmpty(),
check('provider', 'No es un Id de Proveedor Válido').isMongoId(),
check('barCode', 'El Código de producto es obligatorio').not().isEmpty(),
check('barCode').custom( productBarCodeExists ),
],
validateOrDeleteProductImages,
newProduct
);
And when trying to create a new product I get this error from Mongoose:
And even if I pass some random string, it still indicates the error but the validation of express validator is never executed.
Thanks for your help.