How to use the express-validator.check function in express-validator

To help you get started, we’ve selected a few express-validator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github penglin0613 / bigEvents / router / article / articleRouter.js View on Github external
code: 400,
      msg: "文章封面没有上传,请检查"
    })
  }
  next()
}

// 注册路由 - 发布文章
router.post(
  "/publish",
  typeCheck,
  [
    check("title")
      .not()
      .isEmpty(),
    check("categoryId")
      .not()
      .isEmpty(),
    check("date")
      .not()
      .isEmpty(),
    check("content")
      .not()
      .isEmpty()
  ],
  errorMsg,
  fileCheck,
  articleController.publish
)

// 注册路由 - 根据id获取文章
router.get(
github penglin0613 / bigEvents / router / article / articleRouter.js View on Github external
"/search",
  [
    check("id")
      .not()
      .isEmpty()
  ],
  errorMsg,
  articleController.search
)

// 注册路由 - 编辑文章
router.post("/edit", typeCheck,[
  check("id")
  .not()
  .isEmpty(),
  check("title")
    .not()
    .isEmpty(),
  check("categoryId")
    .not()
    .isEmpty(),
  check("date")
    .not()
    .isEmpty(),
  check("content")
    .not()
    .isEmpty()
],errorMsg,articleController.edit)


// 注册路由 - 删除文章
router.use('/delete',[
github OriginProtocol / origin / infra / bridge / src / utils / validation.js View on Github external
const { check, validationResult } = require('express-validator')
const Web3 = require('web3')

const handleValidationError = (req, res, next) => {
  const errors = validationResult(req)
  if (!errors.isEmpty()) {
    res.status(400).json({
      errors: [errors.array()[0].msg]
    })
  } else {
    next()
  }
}

const identityValidation = check('identity')
  .not()
  .isEmpty()
  .withMessage('Field identity must not be empty.')
  .trim()

const codeValidation = (_, { req }) => {
  if (!req.body.code && !req.body.sid) {
    throw new Error('Field `code` or `sid` must be specified.')
  }

  return true
}

const urlValidation = website => {
  try {
    // The following will throw if the URL is malformed
github penglin0613 / bigEvents / router / article / articleRouter.js View on Github external
// 注册路由 - 编辑文章
router.post("/edit", typeCheck,[
  check("id")
  .not()
  .isEmpty(),
  check("title")
    .not()
    .isEmpty(),
  check("categoryId")
    .not()
    .isEmpty(),
  check("date")
    .not()
    .isEmpty(),
  check("content")
    .not()
    .isEmpty()
],errorMsg,articleController.edit)


// 注册路由 - 删除文章
router.use('/delete',[
  check('id').not().isEmpty()
],errorMsg,articleController._delete)

// 注册路由 - 文章搜索
router.get('/query',articleController.query)


module.exports = router
github OriginProtocol / origin / infra / token-transfer-server / src / controllers / transfer.js View on Github external
})
)

/**
 * Add a transfer request to the database.
 */
router.post(
  '/transfers',
  [
    check('amount')
      .isNumeric()
      .toInt()
      .isInt({ min: 1 })
      .withMessage('Amount must be greater than 0'),
    check('address').custom(isEthereumAddress),
    check('code').custom(isValidTotp),
    ensureLoggedIn
  ],
  asyncMiddleware(async (req, res) => {
    const errors = validationResult(req)
    if (!errors.isEmpty()) {
      return res
        .status(422)
        .json({ errors: errors.array({ onlyFirstError: true }) })
    }

    const unlockDate = getUnlockDate()
    if (!unlockDate || moment.utc() < unlockDate) {
      logger.warn(`Transfer attempted by ${req.user.email} before unlock date`)
      res
        .status(422)
        .send(`Tokens are still locked. Unlock date is ${unlockDate}`)
github OriginProtocol / origin / infra / bridge / src / utils / validation.js View on Github external
.not()
    .isEmpty()
    .withMessage('Field code must not be empty.')
    .trim()
    .toInt(),
  handleValidationError
]

const facebookVerify = oauth2CallbackVerify

const phoneGenerateCode = [
  check('country_calling_code')
    .not()
    .isEmpty()
    .trim(),
  check('phone')
    .not()
    .isEmpty()
    .withMessage('Field phone must not be empty.')
    .trim(),
  check('method', 'Invalid phone verification method.')
    .isIn(['sms', 'call'])
    .trim(),
  handleValidationError
]

const phoneVerifyCode = [
  identityValidation,
  check('country_calling_code')
    .not()
    .isEmpty()
    .withMessage('Field country_calling_code must not be empty.')
github OriginProtocol / origin / infra / token-transfer-server / src / controllers / user.js View on Github external
)
  })
)

router.post(
  '/user',
  [
    check('phone')
      .optional()
      .not()
      .isEmpty()
      .withMessage('Phone must not be empty'),
    check('revisedScheduleAgreedAt')
      .optional()
      .isRFC3339(),
    check('termsAgreedAt')
      .optional()
      .isRFC3339(),
    ensureLoggedIn
  ],
  asyncMiddleware(async (req, res) => {
    const errors = validationResult(req)
    if (!errors.isEmpty()) {
      return res
        .status(422)
        .json({ errors: errors.array({ onlyFirstError: true }) })
    }

    const toUpdate = {}
    if (req.body.phone) {
      toUpdate.phone = req.body.phone
    }
github shanhuiyang / TypeScript-MERN-Starter / server / routes / article.ts View on Github external
import express, { Router } from "express";
import * as controllers from "../controllers/article";
import { check, query } from "express-validator";
import passport from "passport";

const updateArticleValidations = [
    check("title", "toast.article.title_empty").not().isEmpty(),
    check("content", "toast.article.content_empty").not().isEmpty(),
    check("title", "toast.article.title_too_long").isLength({ max: 100 }),
    check("content", "toast.article.content_too_short").isLength({ min: 100 }),
];

const article: Router = express.Router();
article.route("/create").post(
    passport.authenticate("bearer", { session: false }),
    updateArticleValidations,
    controllers.create
);
article.route("/edit").post(
    passport.authenticate("bearer", { session: false }),
    [
        check("author", "toast.user.attack_alert")
            .exists()
            .custom((value, { req }) => value === req.user._id.toString()),
github shanhuiyang / TypeScript-MERN-Starter / server / routes / article.ts View on Github external
check("title", "toast.article.title_empty").not().isEmpty(),
    check("content", "toast.article.content_empty").not().isEmpty(),
    check("title", "toast.article.title_too_long").isLength({ max: 100 }),
    check("content", "toast.article.content_too_short").isLength({ min: 100 }),
];

const article: Router = express.Router();
article.route("/create").post(
    passport.authenticate("bearer", { session: false }),
    updateArticleValidations,
    controllers.create
);
article.route("/edit").post(
    passport.authenticate("bearer", { session: false }),
    [
        check("author", "toast.user.attack_alert")
            .exists()
            .custom((value, { req }) => value === req.user._id.toString()),
        ...updateArticleValidations
    ],
    controllers.update
);
article.route("/").get(controllers.read);
article.route("/remove/:id").get(
    passport.authenticate("bearer", { session: false }),
    controllers.remove
);
article.route("/rate").get(
    passport.authenticate("bearer", { session: false }),
    [
        query("id", "toast.user.attack_alert").not().isEmpty(),
        query("rating", "toast.user.attack_alert").isIn(["0", "1"]),