Answers for "oneOf(validationChains[, message])"

0

oneOf(validationChains[, message])

// This protected route must be accessed either by passing both username + password,
// or by passing an access token
app.post(
  '/protected/route',
  oneOf([
    [check('username').exists(), check('password').exists()],
    check('access_token').exists()
  ]),
  someRouteHandler,
);
Posted by: Guest on June-18-2021
0

oneOf(validationChains[, message])

const { check, oneOf, validationResult } = require('express-validator');
app.post('/start-freelancing', oneOf([
  check('programming_language').isIn(['javascript', 'java', 'php']),
  check('design_tools').isIn(['canva', 'photoshop', 'gimp'])
]), (req, res, next) => {
  try {
    validationResult(req).throw();

    // yay! we're good to start selling our skilled services :)))
    res.json(...);
  } catch (err) {
    // Oh noes. This user doesn't have enough skills for this...
    res.status(400).json(...);
  }
});
Posted by: Guest on June-18-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language