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

239
Vistas
Express Validator - If exists for nested array of object
{
    "orderId": "3",
    "storeId": "1",
    "products": [
         "productId": "123",
        {
         "prescriptions" : [{
            "eye": "1",
            "sph": "1",
            "cyl": "1",
            "add": "1",
            "axis": "1"
        }],
            "lensItems": {
                "lensId": "1",
                "lensType": "1",
                "lensCoating": "1",
                "index": "1",
                "price": "3000"
            },
            "frameSize": {
                "a": "1",
                "b": "1",
                "ed": "1",
                "fh": "1",
                "d": "2"
            },
            "counterSale": false
        }
    ]
}

I want to check the prescriptions only if the lensItems exists.

I have tried this,

 body('products.*.prescriptions')
        .if(body('products.*.lensItems').exists())
        .exists()
        .withMessage('prescriptions not exists')
        .isArray()
        .withMessage('prescriptions is not an array')
        .notEmpty()
        .withMessage('prescriptions is empty'),

Its working when I check with string like below,

 body('products.*.prescriptions')
            .if(body('products.*.productId').exists())
            .exists()
            .withMessage('prescriptions not exists')
            .isArray()
            .withMessage('prescriptions is not an array')
            .notEmpty()
            .withMessage('prescriptions is empty'),

I want to the compare array of object with object . If any more regarding this please comment, I will share you much informations which are possible. Thanks in advance

about 4 years ago · Juan Pablo Isaza
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