text: const Config = require('../config/env.config');
  
  const ADMIN = Config.permissionLevels.ADMIN;
  
  exports.minimumPermissionLevelRequired = (required_permission_level) => {
      return (req, res, next) => {
          let user_permission_level = parseInt(req.jwt.permissionLevel);
          if (user_permission_level >= required_permission_level) {
              return next();
          } else {
              return res.status(403).send();
          }
      };
  };
  
  exports.onlySameUserOrAdminCanDoThisAction = (req, res, next) => {
  
      let user_permission_level = parseInt(req.jwt.permissionLevel);
      let userId = req.jwt.userId;
      if (req.params && req.params.userId && userId === req.params.userId) {
          return next();
      } else {
          if (user_permission_level & ADMIN) {
              return next();
          } else {
              return res.status(403).send();
          }
      }
  };
  
  exports.sameUserCantDoThisAction = (req, res, next) => {
      let userId = req.jwt.userId;
  
      if (req.params.userId !== userId) {
          return next();
      } else {
          return res.status(400).send();
      }
  };
  