如何使用快速验证器来确保正文或查询仅包含某些字段?例如:
const { body, query } = require('express-validator/check')
body.containsOnly("field1", "field2", "field3")
query.containsOnly("queryParam1", "queryParam2")
答案 0 :(得分:0)
let fields = ['field1', 'field2'];
function validateBody(body, fields) {
for(key of fields) {
if(!body.hasOwnProperty(key))
return false;
}
return true
}
您可以使用类似的东西