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