{"size": 498, "ext": "js", "max_stars_repo_path": "server/controllers/user/userMiddleware.js", "max_stars_repo_name": "24RMS42/angular-messaging", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/controllers/user/userMiddleware.js", "max_issues_repo_name": "24RMS42/angular-messaging", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server/controllers/user/userMiddleware.js", "max_forks_repo_name": "24RMS42/angular-messaging", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.75, "max_line_length": 74, "alphanum_fraction": 0.6546184739}
const _ = require('lodash');
const mongoose = require('mongoose');
const { catchErrors } = require('../../utils/error');

const { userNotFoundError } = require('./../../common/errors/userErrors');

const User = mongoose.model('User');

const loadUser = async (req, res, next) => {
  const user = await User.findById(res.locals.user.id);

  if (!user) {
    return next(userNotFoundError);
  }

  res.locals.user = user;

  return next();
};

module.exports = {
  loadUser: catchErrors(loadUser)
};
