How to use the express-validator.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 davellanedam / node-express-mongodb-jwt-rest-api-skeleton / app / controllers / profile.js View on Github external
exports.changePassword = async (req, res) => {
  try {
    const id = await utils.isIDGood(req.user._id)
    const user = await findUser(id)
    req = matchedData(req)
    const isPasswordMatch = await auth.checkPassword(req.oldPassword, user)
    if (!isPasswordMatch) {
      utils.handleError(res, await passwordsDoNotMatch())
    } else {
      // all ok, proceed to change password
      res.status(200).json(await changePasswordInDB(id, req))
    }
  } catch (error) {
    utils.handleError(res, error)
  }
}
github NERC-CEH / datalab / code / workspaces / infrastructure-api / src / controllers / stackController.js View on Github external
function deleteStackExec(request, response) {
  // Build request params
  const { user } = request;
  const params = matchedData(request);

  const { projectKey, name } = params;

  return stackRepository.userCanDeleteStack(projectKey, user, name)
    .then((result) => {
      if (result) {
        // Handle request
        return stackManager.deleteStack(user, params)
          .then(controllerHelper.sendSuccessfulDeletion(response))
          .catch(controllerHelper.handleError(response, 'deleting', TYPE, params.name));
      }
      return Promise.reject();
    })
    .catch(controllerHelper.handleError(response, 'deleting', TYPE, params.name));
}
github NERC-CEH / datalab / code / workspaces / infrastructure-api / src / controllers / stackController.js View on Github external
function getOneByNameExec(request, response) {
  // Build request params
  const { user } = request;
  const params = matchedData(request);

  // Handle request
  return stackRepository.getOneByName(params.projectKey, user, params.name)
    .then(handleId)
    .then(stack => response.send(stack))
    .catch(controllerHelper.handleError(response, 'matching Name for', TYPE, undefined));
}
github davellanedam / node-express-mongodb-jwt-rest-api-skeleton / app / controllers / auth.js View on Github external
exports.forgotPassword = async (req, res) => {
  try {
    // Gets locale from header 'Accept-Language'
    const locale = req.getLocale()
    const data = matchedData(req)
    await findUser(data.email)
    const item = await saveForgotPassword(req)
    emailer.sendResetPasswordEmailMessage(locale, item)
    res.status(200).json(forgotPasswordResponse(item))
  } catch (error) {
    utils.handleError(res, error)
  }
}
github puncoz-official / nodejs-express-mvc / src / app / controllers / users / index.js View on Github external
async create(req, res) {
        const user = await UserRepository.setTransformer(UserTransformer).create(matchedData(req))

        this.sendResponse(res, user)
    }
github NERC-CEH / datalab / code / workspaces / infrastructure-api / src / controllers / volumeController.js View on Github external
async function removeUsers(request, response, next) {
  const { projectKey, name, userIds } = matchedData(request);

  try {
    const volume = await dataStorageRepository.removeUsers(request.user, projectKey, name, userIds);
    response.send(volume);
  } catch (error) {
    next(new Error(`Unable to remove users from project ${projectKey} volume ${name}: ${error.message}`));
  }
}
github davellanedam / node-express-mongodb-jwt-rest-api-skeleton / app / controllers / users.js View on Github external
exports.updateItem = async (req, res) => {
  try {
    req = matchedData(req)
    const id = await utils.isIDGood(req.id)
    const doesEmailExists = await emailer.emailExistsExcludingMyself(
      id,
      req.email
    )
    if (!doesEmailExists) {
      res.status(200).json(await db.updateItem(id, model, req))
    }
  } catch (error) {
    utils.handleError(res, error)
  }
}
github NERC-CEH / datalab / code / workspaces / infrastructure-api / src / controllers / stacksController.js View on Github external
function listByCategoryExec(request, response) {
  const { user } = request;
  const params = matchedData(request);

  return stackRepository.getAllByCategory(params.projectKey, user, params.category)
    .then(mapHandleId)
    .then(stacks => response.send(stacks))
    .catch(controllerHelper.handleError(response, 'retrieving by category for', TYPE, undefined));
}
github NERC-CEH / datalab / code / workspaces / infrastructure-api / src / controllers / volumeController.js View on Github external
async function listProjectActiveVolumes(request, response) {
  const { projectKey } = matchedData(request);
  const volumes = await dataStorageRepository.getAllProjectActive(request.user, projectKey);
  response.send(volumes);
}
github NERC-CEH / datalab / code / workspaces / infrastructure-api / src / controllers / projectsController.js View on Github external
async function getProjectByKey(request, response, next) {
  const { projectKey } = matchedData(request);

  try {
    const project = await projectsRepository.getByKey(projectKey);
    if (project) {
      response.send(project);
    } else {
      response.status(404).send();
    }
  } catch (error) {
    next(new Error(`Error getting project by key: ${error.message}`));
  }
}