How to use the express-validator/filter.matchedData 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 NERC-CEH / datalab / code / infrastructure-api / src / controllers / proxyController.js View on Github external
function createRouteExec(request, response) {
  // Build request params
  const { name, datalab, port } = matchedData(request);

  return proxyRouteApi.createOrUpdateRoute(name, datalab, port)
    .then(controllerHelper.sendSuccessfulCreation(response))
    .catch(controllerHelper.handleError(response, 'creating', TYPE, name));
}
github mariocoski / express-typescript-react-redux-universal / api / build / controllers / TodosController.js View on Github external
return __generator(this, function (_a) {
        switch (_a.label) {
            case 0:
                errors = utils_1.getErrors(req);
                if (!errors.isEmpty()) {
                    return [2 /*return*/, res.status(422).json({ errors: errors.mapped() })];
                }
                data = __assign({}, filter.matchedData(req), { user_id: req.user.id, completed_at: null, deleted_at: null });
                return [4 /*yield*/, todoRepo_1.createTodo(data)];
            case 1:
                _a.sent();
                res.status(201).json({ created: true });
                return [2 /*return*/];
        }
    });
}); });
github byteball / ico-bot / server / routes / index.js View on Github external
], (req, res) => {
	const objErrors = validationResult(req);
	if (!objErrors.isEmpty()) {
		return res.status(422).json({ errors: objErrors.mapped() });
	}

	const data = matchedData(req);

	let arrParams = [];

	let strSqlWhere = 'stable = 1';
	let nRoundDisplayDecimals = conf.tokenDisplayDecimals;
	if (data.filter_currency && data.filter_currency !== 'all') {
		strSqlWhere += ' AND currency = ?';
		arrParams.push(data.filter_currency);
		nRoundDisplayDecimals = getNumberRoundDisplayDecimalsOfCurrency(data.filter_currency);
	}
	if (data.filter_date_from && data.filter_date_to) {
		strSqlWhere += ' AND paid_date BETWEEN ? AND ?';
		arrParams.push(
			moment(data.filter_date_from).format('YYYY-MM-DD 00:00:01'), 
			moment(data.filter_date_to).format('YYYY-MM-DD 23:59:59')
		);
github mariocoski / express-typescript-react-redux-universal / api / src / controllers / AuthController.ts View on Github external
const register = catchErrors(async (req: Request, res: Response) => {

  const errors = getErrors(req);
  if (!errors.isEmpty()) {
    return res.status(422).json({ errors: errors.mapped() });
  }

  const data: any = filter.matchedData(req);

  const user = await findUserByEmail(data.email);

  if(user){  
    return res.status(422).json(formatError(EMAIL_ALREADY_IN_USE));
  }

  const token: string = await generateRandomToken();
  const createdUser = await createUser({...data, verify_token: token});
  const userModel = createdUser.get({ plain: true });
  
  await associateRole(userModel.id, getRoleId(USER_ROLE));

  const userInfo = {
    _id: userModel.id,
    first_name: userModel.first_name,
github jolicode / Harvest-Forecast-tools / routes / insert.js View on Github external
assignements,
                });
              })
              .catch(reason => {
                return buildForm(req, res, next, values, { global: reason });
              });
          })
          .catch(err => {
            throw err;
          });
      })
      .catch(reason => {
        return buildForm(req, res, next, values, { global: reason });
      });
  } catch (err) {
    const values = matchedData(req, { onlyValidData: false });
    return buildForm(req, res, next, values, err.mapped());
  }
});
github mariocoski / express-typescript-react-redux-universal / api / src / controllers / ProfileController.ts View on Github external
const update = catchErrors(async (req: Request, res: Response) => {
  
  const user = req.user;

  if(user.id.toString() !== req.params.userId){
    throw new UnauthorizedError();
  }

  const errors = getErrors(req);

  if(!errors.isEmpty()) {
    return res.status(422).json({ errors: errors.mapped() });
  }
  const data: any = filter.matchedData(req);

  await updateUser(user.id, data);

  res.status(200).json({ updated: true});
});
github mariocoski / express-typescript-react-redux-universal / api / build / controllers / ProfileController.js View on Github external
return __generator(this, function (_a) {
        switch (_a.label) {
            case 0:
                user = req.user;
                if (user.id.toString() !== req.params.userId) {
                    throw new errors_1.UnauthorizedError();
                }
                errors = utils_1.getErrors(req);
                if (!errors.isEmpty()) {
                    return [2 /*return*/, res.status(422).json({ errors: errors.mapped() })];
                }
                data = filter.matchedData(req);
                return [4 /*yield*/, userRepo_1.updateUser(user.id, data)];
            case 1:
                _a.sent();
                res.status(200).json({ updated: true });
                return [2 /*return*/];
        }
    });
}); });
github hackmcgill / hackerAPI / middlewares / parse-body.middleware.js View on Github external
function middleware(req, res, next) {
    const errors = validationResult(req);
    if (!errors.isEmpty()) {
        return next({
            status: 422,
            message: Constants.Error.VALIDATION_422_MESSAGE,
            data: errors.mapped()
        });
    }
    req.body = matchedData(req);
    return next();
}
github mariocoski / express-typescript-react-redux-universal / api / build / controllers / AuthController.js View on Github external
return __generator(this, function (_d) {
        switch (_d.label) {
            case 0:
                errors = utils_1.getErrors(req);
                if (!errors.isEmpty()) {
                    return [2 /*return*/, res.status(422).json({ errors: errors.mapped() })];
                }
                data = filter.matchedData(req);
                return [4 /*yield*/, userRepo_1.findUserByResetPasswordToken(data.token)];
            case 1:
                user = _d.sent();
                if (!user) {
                    return [2 /*return*/, res.status(422).json(utils_1.formatError(errors_1.INVALID_PASSWORD_RESET_TOKEN))];
                }
                olderThanOneHour = (Date.now() - (new Date(user.password_reset_token_expired_at).getTime())) > constants_1.ONE_HOUR;
                if (olderThanOneHour) {
                    return [2 /*return*/, res.status(422).json(utils_1.formatError(errors_1.EXPIRED_PASSWORD_RESET_TOKEN))];
                }
                _b = (_a = user).update;
                _c = {
                    password_reset_token: null,
                    password_reset_token_expired_at: null
                };
                return [4 /*yield*/, utils_2.generateHash(data.password)];
github mariocoski / express-typescript-react-redux-universal / api / src / controllers / TodosController.ts View on Github external
const updateTodo = catchErrors(async (req: Request, res: Response) => {

  const errors = getErrors(req);
  
  if(!errors.isEmpty()) {
    return res.status(422).json({ errors: errors.mapped() });
  }
  
  const data: any = filter.matchedData(req);
  
  const todoId = req.params.todoId;

  const todo = await getTodoById(todoId);

  if(todo.user_id !== req.user.id){
    throw new ForbiddenError();
  }

  await updateTodoById(todoId, data);

  res.status(200).json({ updated: true });
});