Created
August 28, 2021 20:03
-
-
Save buildmotion/e1bdce1a0ab8b6bcb3e15d36940edefc to your computer and use it in GitHub Desktop.
This file contains 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
import {RulePolicy} from './RulePolicy'; | |
import {RuleResult} from './RuleResult'; | |
export class CompositeRule extends RulePolicy { | |
hasErrors: boolean = false; | |
results: Array<RuleResult> = new Array<RuleResult>(); | |
rules: Array<RulePolicy> = new Array<RulePolicy>(); | |
constructor(name: string, message: string, isDisplayable: boolean) { | |
super(name, message, isDisplayable); | |
} | |
render(): RuleResult { | |
this.rules.sort(s => s.priority).forEach(r => this.results.push(r.execute())); | |
return this.processResults(); | |
} | |
public hasRules(): boolean { | |
if (this.rules && this.rules.length > 0) { | |
return true; | |
} | |
return false; | |
} | |
processResults(): RuleResult { | |
if (this.results.filter(r => (r.isValid === false)).length > 0) { | |
this.isValid = false; | |
this.hasErrors = true; | |
} | |
return new RuleResult(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment