[英]Limit and Offset Joi valdation
如何檢查是否同時提供了 limit 和 offset 或都不提供
limit: Joi.number().integer(),
offset: Joi.when('limit' ,{is: Joi.exist(),
then: Joi.number().integer().required()}),
//This is working if limit is provided check for offset
嘗試:
limit: Joi.when('offset', {
is: Joi.exist(),
then: Joi.number().integer().required()
}),
offset: Joi.when('limit', {
is: Joi.exist(),
then: Joi.number().integer().required()
})
這樣做,將同時需要兩個字段。
limit: Joi.number().integer(),
offset: Joi.when('limit', {
is: Joi.exist(),
then: Joi.number().integer().required(),
otherwise: Joi.any().forbidden().error(new Error("need limit and offset both"))
}),
這是工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.