节点JS Express验证器 - 使用'检查'只有IF条件为真

时间:2018-06-16 18:35:00

标签: node.js express-validator

我正在应用Node JS Express-validator。我需要检查'只有在条件成立时才能工作。

我可以做到以下几点 - 它运作正常。但有没有办法使用纯粹的Express-validator语法来做同样的事情?

exports.type_create_post = [

    check('infotype').custom((infotype, { req }) => {
      if ( infotype == "webpage" ) {
        if (req.body.url.length>0 && !isURL(req.body.url)) return Promise.reject('Webpage is not valid');
        if (req.body.url.length==0) return Promise.reject('Webpage is required');
      }
      return Promise.resolve('valid');
    }),

(req, res, next) => {

0 个答案:

没有答案