【发布时间】:2020-11-13 10:37:46
【问题描述】:
我正在尝试验证通过 JSON 请求中的对象数组传递的数据。我使用了文档中指定的 express-validator 通配符,但无论对象的属性是否为空,都会返回错误消息。我已经在网上检查了各种解决方案,试图调试这个问题,但都无济于事。如果有人能指出我做错了什么并提出正确的解决方案,我将不胜感激,谢谢。
验证
body("*.product", "Invalid or Empty Product Details").trim().notEmpty(),
body("*.price", "Invalid or Empty Product Price").trim().notEmpty(),
body("*.customer", "Invalid or Empty Customer Details")
.trim()
.notEmpty(),
body("*.seller", "Invalid or Empty Seller Details").trim().notEmpty(),
body("*.haulageOptions", "Invalid or Empty Haulage Options").trim().notEmpty()
JSON 请求
{
"order": [
{
"product": {
"commodity": "",
"quantity": ""
},
"price": {
"orderPrice": "",
"deliveryPrice": "",
"totalPrice": ""
},
"customer": {
"name": "",
"email": "",
"location": {
"state": "",
"localGovernment": "",
"town": "",
"address": ""
}
},
"seller": {
"name": "",
"phone": [
""
],
"email": ""
},
"haulageOptions": {
"firstOrder": "",
"secondOrder": "",
"thirdOrder": ""
}
}
]
}
【问题讨论】:
标签: express validation object express-validator