Created
February 26, 2020 18:36
-
-
Save sgoguen/a4e70b68560ff225a73b21811c2ea43f to your computer and use it in GitHub Desktop.
Typescript Translation of Jeff's Snippet
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
| enum TrustLevel { | |
| None, | |
| AcceptAllSolutionsTrustLevel | |
| } | |
| class SomeComponent { | |
| private authenticated = false; | |
| private isStaff = false; | |
| private currentUser = { | |
| id: 123, | |
| trustLevel: TrustLevel.AcceptAllSolutionsTrustLevel | |
| }; | |
| public canAcceptAnswer(topic, post) { | |
| if (!this.authenticated) { return false; } | |
| if (!topic || !post || post.whisper) { return false; } | |
| if (!this.allowAcceptedAnswersOnCategory(topic.categoryId)) { return false; } | |
| if (this.isStaff) { return true; } | |
| if (this.currentUser.trustLevel >= TrustLevel.AcceptAllSolutionsTrustLevel) { return true; } | |
| return topic.userId === this.currentUser.id && !topic.closed; | |
| } | |
| public allowAcceptedAnswersOnCategory(categoryId) { | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment