I'm trying to check user access level to grant him some actions in the service.
exports.hasAdminAccess = function(req, res, next) {
if (hasAccessLevel(req.user, adminLevel)) {
return next()
}
res.redirect('/accessProblem');
}
function hasAccessLevel(user, level) {
UserRole = models.UserRole;
return UserRole.findOne({
where: {
id: user.userRoleId,
}
}).then(function(role){
if (role.accessLevel <= level) {
return true;
} else {
return false;
}
});
}
but hasAccessLevel()
is constantly returning Promise
object instead true
or false
.
I could write body of hasAccessLevel
in hasAdminAccessLevel
, but I have plenty of other methods for other roles.
Are there any other ways to perform this operation?