Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Roles {
- public name: string;
- public permissions: Array<string>;
- public blockedPermissions: Array<string>;
- constructor(name: string, permissions: Array<string> = [], blockedPermissions: Array<string> = []) {
- this.name = name;
- this.permissions = permissions;
- this.blockedPermissions = blockedPermissions;
- }
- createPermission(permissionName: string): Roles {
- this.permissions.push(permissionName);
- return this;
- }
- removePermission(permissionName: string): void {
- this.permissions = this.permissions.filter((role) => role !== permissionName);
- }
- blockPermission(permissionName: string): void {
- const isPermissionExists = this.permissions.find((permission) => permission === permissionName);
- if (isPermissionExists) {
- this.removePermission(permissionName);
- }
- this.blockedPermissions.push(permissionName);
- }
- }
- export default Roles;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement