3 つのパラメーターがあります。latitude, longitude, zipcode
私はjoi検証が必要です
- いずれかが存在する場合、または郵便番号が欠落している場合は、緯度と経度が必要です
- 緯度または経度のいずれかが欠落している場合、郵便番号が必要です。
このようなもの?
Joi.object().keys({
latitude: Joi.number().when('zipcode', { is: undefined, then: Joi.required() }),
longitude: Joi.number().when('zipcode', { is: undefined, then: Joi.required() }),
zipcode: Joi.number().when(['latitude', 'longitude'], { is: undefined, then: Joi.required() })
});
おそらくobject.and()を使用するよりエレガントなソリューションがあると思います