Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

449
Views
¿Cómo puedo asegurarme de que una matriz de objetos contenga solo uno de una clave particular con Joi?

tengo algo como:

 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.' ]) } })

Quiero convertir esto a un esquema Joi . ¿Cómo lograría esto?

Gracias

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede usar el método Joi.array y pasarle solo una clave que le gustaría que tuviera el objeto

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

over 4 years ago · Santiago Trujillo Report

0

Esto se puede lograr de la siguiente manera:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!