How to use the express-validator.param 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 cloudfoundry / overview-broker / service_broker_interface.js View on Github external
deleteServiceInstance() {
        return [
            param('instance_id', 'Missing instance_id').exists(),
            query('service_id', 'Missing service_id').exists(),
            query('plan_id', 'Missing plan_id').exists(),
                (request, response, next) => {
                const errors = validationResult(request);
                if (!errors.isEmpty()) {
                    this.sendJSONResponse(response, 400, { error: JSON.stringify(errors) });
                    return;
                }

                // Validate serviceId and planId
                var plan = this.serviceBroker.getPlanForService(request.query.service_id, request.query.plan_id);
                if (!plan) {
                    // Just throw a warning in case the broker was restarted so the IDs changed
                    console.warn('Could not find service %s, plan %s', request.query.service_id, request.query.plan_id);
                }
github cloudfoundry / overview-broker / service_broker_interface.js View on Github external
createServiceBinding() {
        return [
            param('instance_id', 'Missing instance_id').exists(),
            body('service_id', 'Missing service_id').exists(),
            body('plan_id', 'Missing plan_id').exists(),
            (request, response, next) => {
                const errors = validationResult(request);
                if (!errors.isEmpty()) {
                    this.sendJSONResponse(response, 400, { error: JSON.stringify(errors) });
                    return;
                }

                var serviceInstanceId = request.params.instance_id;
                var bindingId = request.params.binding_id;

                // Check that the instance already exists
                if (!this.serviceInstances[serviceInstanceId]) {
                    this.sendJSONResponse(response, 404, { error: `Could not find service instance ${serviceInstanceId}` });
                    return;
github cloudfoundry / overview-broker / service_broker_interface.js View on Github external
getServiceInstance() {
        return [
            param('instance_id', 'Missing instance_id').exists(),
            (request, response, next) => {
                const errors = validationResult(request);
                if (!errors.isEmpty()) {
                    this.sendJSONResponse(response, 400, { error: JSON.stringify(errors) });
                    return;
                }

                let serviceInstanceId = request.params.instance_id;
                if (!this.serviceInstances[serviceInstanceId]) {
                    this.sendJSONResponse(response, 404, { error: `Could not find service instance ${serviceInstanceId}` });
                    return;
                }

                var data = Object.assign({}, this.serviceInstances[serviceInstanceId].data);
                data.service_id = this.serviceInstances[serviceInstanceId].service_id;
                data.plan_id = this.serviceInstances[serviceInstanceId].plan_id;
github WagonOfDoubt / kotoba.js / app / src / routes / manage / news.js View on Github external
const newsList = await News.find().sort({ createdAt: -1 });
      res.render('manage/news', {
        activity: 'manage-page-editnews',
        newsList: newsList,
        title: 'News',
        crud: 'read',
      });
    } catch (err) {
      next(err);
    }
  }
);

router.get('/news/edit/:newsId',
  authRequired,
  param('newsId').isNumeric(),
  validateRedirect('/manage/news'),
  async (req, res, next) => {
    try {
      const newsId = req.params.newsId;
      const news = await News.findOne({ number: newsId });
      if (!news) {
        return res.redirect('/manage/news');
      }
      res.render('manage/news', {
        activity: 'manage-page-editnews',
        news: news,
        title: 'Edit news',
        crud: 'update',
      });
    } catch (err) {
      next(err);
github NERC-CEH / datalab / code / workspaces / infrastructure-api / src / controllers / projectsController.js View on Github external
const urlAndBodyProjectKeyMatchValidator = () => service.middleware.validator([
  param('projectKey')
    .custom((projectKey, { req }) => {
      if (projectKey !== req.body.key) {
        throw new Error("'projectKey' parameter in URL and 'key' field in request body must "
      + `match. Got '${projectKey}' in URL and '${req.body.key}' in body.`);
      }
      return true;
    }),
], logger);
github cloudfoundry / overview-broker / service_broker_interface.js View on Github external
updateServiceInstance() {
        return [
            param('instance_id', 'Missing instance_id').exists(),
            body('service_id', 'Missing service_id').exists(),
            (request, response, next) => {
                const errors = validationResult(request);
                if (!errors.isEmpty()) {
                    this.sendJSONResponse(response, 400, { error: JSON.stringify(errors) });
                    return;
                }

                var serviceInstanceId = request.params.instance_id;

                var plan = null;
                if (request.body.plan_id) {
                    plan = this.serviceBroker.getPlanForService(request.body.service_id, request.body.plan_id);
                } else {
                    let service_id = this.serviceInstances[serviceInstanceId].service_id;
                    let plan_id = this.serviceInstances[serviceInstanceId].plan_id;
github hackmcgill / hackerAPI / middlewares / validators / validator.helper.js View on Github external
* check: ValidationChainBuilder;
     * body: ValidationChainBuilder;
     * cookie: ValidationChainBuilder;
     * header: ValidationChainBuilder;
     * param: ValidationChainBuilder;
     * query: ValidationChainBuilder;
     */
    switch (fieldLocation) {
        case "query":
            return query(fieldName, errorString);
        case "body":
            return body(fieldName, errorString);
        case "header":
            return header(fieldName, errorString);
        case "param":
            return param(fieldName, errorString);
        default:
            logger.error(`${TAG} Invalid field location: ${fieldLocation}`);
    }
}
github cloudfoundry / overview-broker / service_broker_interface.js View on Github external
getLastServiceBindingOperation() {
        return [
            param('instance_id', 'Missing instance_id').exists(),
            param('binding_id', 'Missing binding_id').exists(),
            (request, response, next) => {
                const errors = validationResult(request);
                if (!errors.isEmpty()) {
                    this.sendJSONResponse(response, 400, { error: JSON.stringify(errors) });
                    return;
                }
                var bindingId = request.params.binding_id;
                var operation = this.bindingOperations[bindingId];
                this.getLastOperation(operation, bindingId, request, response);
            }
        ]
    }
github cloudfoundry / overview-broker / service_broker_interface.js View on Github external
getInfo() {
        return [
            param('instance_id', 'Missing instance_id').exists(),
            (request, response, next) => {
                const errors = validationResult(request);
                if (!errors.isEmpty()) {
                    this.sendJSONResponse(response, 400, { error: JSON.stringify(errors) });
                    return;
                }

                let serviceInstanceId = request.params.instance_id;
                if (!this.serviceInstances[serviceInstanceId]) {
                    this.sendJSONResponse(response, 404, { error: `Could not find service instance ${serviceInstanceId}` });
                    return;
                }

                let data = {
                    server_url: cfenv.getAppEnv().url,
                    npm_config_node_version: process.env.npm_config_node_version,