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

458
Visualizações
How can I ensure that an array of objects contains only one of a particular key with Joi?

I have something like:

  let moduleId

  moduleRackOutputs.forEach((output) => {
    if (!moduleId) {
      moduleId = output.moduleId
    } else if (output.moduleId !== moduleId) {
      errors.add([
        'The drawing contains more than one module type. Multiple module types are not yet supported by the PVsyst RPA.'
      ])
    }
  })

I want to convert this to a Joi schema. How would I accomplish this?

Thank you

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can use the Joi.array method and pass it only one key you would like the object to have

const schema = Joi.object({
    arrayObjects: Joi.array().items(
      Joi
      .object()
      .keys(
        {keyElement:Joi.string()}
        )
     )
});

over 4 years ago · Santiago Trujillo Relatório

0

This can be accomplished as follows:

Joi.array()
    .items(
        Joi.object().keys({
            moduleId: Joi.string().required(),
            framingType: Joi.string().required()
        })
    )
    .unique((a, b) => a.moduleId !== b.moduleId)
    .message({
        'array.unique': 'The drawing contains more than one module type...'
    })
    .unique((a, b) => a.framingType !== b.framingType)
    .message({
        'array.unique': 'The drawing contains more than one framing type...'
    })
over 4 years ago · Santiago Trujillo Relatório
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