-1

i have form request like this

{
    "data": [
        {
            "transaction": "LNS",
            "product": "XXX",
            "lot": "1",
            "liquidPrice": "0",
            "liquidId": 0,
            "limitPrice": "1780.00",
            "stopPrice": "0"
        },
        {
            "transaction": "LNS",
            "product": "XXX",
            "lot": "1",
            "liquidPrice": "0",
            "liquidId": 0,
            "limitPrice": "1780.00",
            "stopPrice": "0"
        }
    ]
}

i want to check if the array data bigger than one object, the value of key object product must same as another array of object

2 Answers2

1

You can follow these steps for check of key object

  1. Compare each and every element of two arrays.
  2. Return the matched element.
  3. Add the element or object into the object of array.

Check this example :

let Joi = require('joi')
let service = Joi.object().keys({
  serviceName: Joi.string().required(),
})

let services = Joi.array().items(service)

let test = Joi.validate(
  [{ serviceName: 'service1' }, { serviceName: 'service2' }],
  services,
)
Manish Kumar
  • 111
  • 6
0

you using Joi validation libary:

Joi.array().items({
     "transaction": Joi.string().required(),
      ...
}).min(1)
0xcuonghx
  • 450
  • 5
  • 4