Advertisement
ynhhoJ

Roles.ts

May 5th, 2021
1,448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Roles {
  2.   public name: string;
  3.  
  4.   public permissions: Array<string>;
  5.  
  6.   public blockedPermissions: Array<string>;
  7.  
  8.   constructor(name: string, permissions: Array<string> = [], blockedPermissions: Array<string> = []) {
  9.     this.name = name;
  10.     this.permissions = permissions;
  11.     this.blockedPermissions = blockedPermissions;
  12.   }
  13.  
  14.   createPermission(permissionName: string): Roles {
  15.     this.permissions.push(permissionName);
  16.  
  17.     return this;
  18.   }
  19.  
  20.   removePermission(permissionName: string): void {
  21.     this.permissions = this.permissions.filter((role) => role !== permissionName);
  22.   }
  23.  
  24.   blockPermission(permissionName: string): void {
  25.     const isPermissionExists = this.permissions.find((permission) => permission === permissionName);
  26.  
  27.     if (isPermissionExists) {
  28.       this.removePermission(permissionName);
  29.     }
  30.  
  31.     this.blockedPermissions.push(permissionName);
  32.   }
  33. }
  34.  
  35. export default Roles;
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement