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

163
Views
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
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!