30 lines
707 B
JavaScript
30 lines
707 B
JavaScript
const ENUM = require('./const.js');
|
|
|
|
function getUserGroupByRole(userRole) {
|
|
const role = ENUM.user.role;
|
|
userRole = Number(userRole);
|
|
let userGroupDict = {
|
|
'visitor': [
|
|
role.VISITOR,
|
|
].includes(userRole),
|
|
'user': [
|
|
role.RESIDENTS_OWNER,
|
|
role.RESIDENTS_MEMBER,
|
|
role.RESIDENTS_TENENT,
|
|
].includes(userRole),
|
|
'admin': [
|
|
role.ADMIN,
|
|
role.STAFF,
|
|
].includes(userRole)
|
|
}
|
|
console.log("userGroupDict", userGroupDict, userRole, role)
|
|
for (let userGroup of Object.keys(userGroupDict)) {
|
|
if (userGroupDict[userGroup]) {
|
|
return userGroup;
|
|
}
|
|
}
|
|
return 'unknown';
|
|
}
|
|
|
|
module.exports = getUserGroupByRole;
|