Created
January 18, 2026 09:33
-
-
Save davorg/9893686ce3b4d44aea9b0d1114c1179c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User { | |
| constructor({ isActive, role, isSuspended } = {}) { | |
| this.isActive = isActive; | |
| this.role = role; | |
| this.role = role; | |
| this.isSuspended = isSuspended; | |
| } | |
| canAccessAdmin() { | |
| return this.isActive && this.role === "admin" && !this.isSuspended; | |
| } | |
| grantAccess() { | |
| if (!this.canAccessAdmin()) { | |
| throw new Error("User is not permitted to access admin features"); | |
| } | |
| // perform the access-granting work here | |
| } | |
| } | |
| // usage | |
| try { | |
| user.grantAccess(); | |
| } catch (err) { | |
| // handle / log / show error | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment