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

457
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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