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

28 lines
606 B
JavaScript
Raw Normal View History

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