All files / utils userRoles.js

100% Statements 7/7
100% Branches 4/4
100% Functions 3/3
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 294x               4x               4x 20x       6x       5x 5x    
export const USER_ROLE = Object.freeze({
  SUPER_ADMIN: 0,
  ADMIN: 1,
  READER: 2,
  ACQUISITIONS: 3,
  LOGISTICS: 4,
});
 
export const USER_ROLE_OPTIONS = Object.freeze([
  Object.freeze({ value: USER_ROLE.SUPER_ADMIN, label: "超级管理员" }),
  Object.freeze({ value: USER_ROLE.ADMIN, label: "管理员" }),
  Object.freeze({ value: USER_ROLE.READER, label: "读者" }),
  Object.freeze({ value: USER_ROLE.ACQUISITIONS, label: "采购员" }),
  Object.freeze({ value: USER_ROLE.LOGISTICS, label: "物流员" }),
]);
 
const ROLE_NAMES = Object.freeze(
  Object.fromEntries(USER_ROLE_OPTIONS.map(({ value, label }) => [value, label]))
);
 
export function getUserRoleName(role) {
  return ROLE_NAMES[Number(role)] || null;
}
 
export function isAdministratorRole(role) {
  const value = Number(role);
  return value === USER_ROLE.SUPER_ADMIN || value === USER_ROLE.ADMIN;
}