Skip to content

Instantly share code, notes, and snippets.

@sgoguen
Created February 26, 2020 18:36
Show Gist options
  • Save sgoguen/a4e70b68560ff225a73b21811c2ea43f to your computer and use it in GitHub Desktop.
Save sgoguen/a4e70b68560ff225a73b21811c2ea43f to your computer and use it in GitHub Desktop.
Typescript Translation of Jeff's Snippet
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