问题描述
我正在使用 express-validator 在服务器端执行我的后端验证,到目前为止一切顺利,直到我面临一种情况,我想根据前端的用户选择验证模式。下面是我的代码的样子。
shopRoutes.js
router.post('create-product',oneOf([checkSchema.cars,checkSchema.events]),(req,res,next) => {}
架构
checkSchema.cars = {
title: {
in: ['body'],isEmpty: {
errorMessage: "Le champs titre est obligatoire,veuillez saisire un titre."
},isLength: {
options: { min: 3,max: 50 },errorMessage: "Le titre doit avoir au minimum 3 characteres et au plus 50 characteres"
},trim: true,escape: true
}
}
checkSchema.event = {
location: {
in: ['body'],isEmpty: {
negated: true,errorMessage: "Le champs lieu est requis,veuillez selectionner un lieu afin de continuer!"
}
}
}
我遇到的问题是,无论用户选择什么,创建事件或汽车,express-validator 都会验证它们,而不是其中之一,因为我理解 oneOf 的作用。我环顾四周,发现自 2019 年以来就有一个问题在这方面处于开放状态,但此后什么也没有。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)