Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda