{"size": 408, "ext": "js", "max_stars_repo_path": "utils/checkAtLeastLevelOne.js", "max_stars_repo_name": "RaeStichter/paranormal-tourism", "max_stars_repo_stars_event_min_datetime": "2021-02-06T15:20:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-06T15:20:53.000Z", "max_issues_repo_path": "utils/checkAtLeastLevelOne.js", "max_issues_repo_name": "RaeStichter/paranormal-tourism", "max_issues_repo_issues_event_min_datetime": "2021-02-06T17:04:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-15T13:17:32.000Z", "max_forks_repo_path": "utils/checkAtLeastLevelOne.js", "max_forks_repo_name": "RaeStichter/paranormal-tourism", "max_forks_repo_forks_event_min_datetime": "2021-02-06T21:15:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-06T21:15:18.000Z"}
{"max_stars_count": 1, "max_issues_count": 25, "max_forks_count": 1, "avg_line_length": 25.5, "max_line_length": 77, "alphanum_fraction": 0.6397058824}
// express middleware to check that user.level > 1
// sequelize models
const { User } = require('../models');

const atLeastLevelOne = (req, res, next) =>
{
  User.findOne({ where: { id: req.session.user_id }, attributes: ['level'] })
  .then(userData =>
  {
    if (userData.level >= 1) next();
    else res.status(401).json({ message: 'You are not authorized' });
  })
}

module.exports = atLeastLevelOne;
