Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

306
Vistas
Pass two values ​to custom validation with express-validation

I need to receive two values ​​to search for a subdocument using the main ID of the document and then another ID of the subdocument.

I receive these ID's by the parameters and using express-validator I am using a custom function to verify that they exist in this way:

router.put('/:id/item/:idItem',   
    [        
        check('id','idItem').custom( idItemExists )
    ],
    validation,
    updateItem 
);

And in my function called idItemExists() I try to receive both values ​​but the second value, when passed to the console, returns everything that comes from the request:

let idItemExists = async ( id, idItem ) => { 
    console.log(idItem);
}

Response Capture

In this case I need to be able to receive both values ​​correctly in order to validate if both IDs are correct.

Thanks a lot.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

this will not work since .custom takes a function that receives the value of the field being validated, as well as the express request, the location and the field path as mentioned in their docs.

validator(value, { req, location, path })

in your case you're trying to log the object that contains the req, location and the path.

in order to get both values inside a custom validator you could do the following:

 param() // when we omit fields, then we're getting all fields inside req.params
    .custom(params => { // here we ignore the second parameter { req, location, path }
        console.log(params) // { id: '10', idItem: '20' }
    })
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda