opt-cc/api/middleware/permission-check.js

28 lines
612 B
JavaScript
Raw Normal View History

2018-03-12 09:26:44 +01:00
'use strict';
2017-06-08 13:14:53 +02:00
let check = (requiredPermission, actualPermission, res, next) => {
if (actualPermission >= requiredPermission) {
return next();
}
return res.status(403).send({
success: false,
2018-03-12 09:26:44 +01:00
message: 'permission denied',
2017-06-08 13:14:53 +02:00
});
};
module.exports = {
2018-02-26 09:04:27 +01:00
checkSql: (req, res, next) => {
2018-03-12 09:26:44 +01:00
check(1, req.user.permission, res, next);
2018-02-26 09:04:27 +01:00
},
checkHl: (req, res, next) => {
2018-03-12 09:26:44 +01:00
check(2, req.user.permission, res, next);
2018-02-26 09:04:27 +01:00
},
checkMT: (req, res, next) => {
2018-03-12 09:26:44 +01:00
check(3, req.user.permission, res, next);
2018-02-26 09:04:27 +01:00
},
checkAdmin: (req, res, next) => {
2018-03-12 09:26:44 +01:00
check(4, req.user.permission, res, next);
},
2017-06-08 13:14:53 +02:00
};