【发布时间】:2019-04-10 16:18:51
【问题描述】:
我正在尝试验证对端点的请求,使用 express 验证器的 .equals() 检查用户类型的输入是否等于“储蓄”或“当前”。但是 equals() 只选择第一个值。
我尝试使用 ||声明
const creatAccount = [
check('type').not().isEmpty().withMessage('Please specify account type'),
check('type').equals('savings' || 'current').withMessage('Invalid Account Type: Account Type can be either "savings" or "current"'),
check('initialDeposit').not().isEmpty().withMessage('specify a Initial Deposit'),
(req, res, next) => {
const errors = validationResult(req);
const errMessages = [];
if (!errors.isEmpty()) {
errors.array().forEach((err) => {
errMessages.push(err.msg);
});
return res.status(401).json({
status: 401,
error: errMessages,
});
}
return next();
},
]
【问题讨论】:
标签: javascript express endpoint express-validator