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

164
Visualizações
How can I have multiple unique checks with a Joi schema validation?

I have data:

const mockScenario1 = {
  drawingNode: {
    moduleRackOutputs: [
      {
        moduleId: 'module1',
        tilt: 'tilt1',
        rack: {
          framingType: 'framing1'
        }
      },
      {
        moduleId: 'module2',
        tilt: 'tilt1',
        rack: {
          framingType: 'framing1'
        }
      }
    ]
  }
}

I want to ensure that:

  • If there are different moduleId values, I want: Only one module allowed
  • If there are different rack.framingType values, I want: Only one framing type allowed

I have this sort of started with:

Joi.object({
  drawingNode: Joi.object({
    moduleRackOutputs: Joi.array()
      .items(
        Joi.object().keys({
          moduleId: Joi.string().required(),
          tilt: Joi.string().required(),
          rack: Joi.object({
            framingType: Joi.string().required()
          })
        })
      )
      .unique((a, b) => a.moduleId !== b.moduleId)
      .messages({
        'array.unique':
          'The drawing contains more than one module type. Multiple module types are not yet supported by the PVsyst RPA.'
      })
  })
})

Which works for the module, but not the framingType. Seems I can't use multiple unique?

I'd love any help or pointers. Thanks!

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