-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4da25b
commit 3ea35bf
Showing
4 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Context from './Context'; | ||
import Validator from './Validator'; | ||
|
||
export type OnlyChecker<TOuterContext> = (values: any, errors: any, context: Context<TOuterContext>) => boolean; | ||
|
||
class OnlyValidator<TOuterContext = any> extends Validator<TOuterContext> { | ||
protected check: OnlyChecker<TOuterContext>; | ||
|
||
protected validator: Validator<TOuterContext>; | ||
|
||
constructor(check: OnlyChecker<TOuterContext>, validator: Validator<TOuterContext>) { | ||
super(); | ||
this.validator = validator; | ||
this.check = check; | ||
} | ||
|
||
public execute(values: any, errors: any, context: Context<TOuterContext>): any { | ||
if (this.check(values, errors, context)) { | ||
return this.validator.execute(values, errors, context); | ||
} | ||
|
||
return errors; | ||
} | ||
} | ||
|
||
export default OnlyValidator; |
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
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