Skip to content

Commit

Permalink
fix: add default message for isPort validator (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubin Bhandari authored and vlapo committed Aug 19, 2019
1 parent 01aa7f1 commit 74e568c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/validation/ValidationTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ValidationArguments} from "./ValidationArguments";
import { ValidationArguments } from "./ValidationArguments";

/**
* Validation types.
Expand Down Expand Up @@ -102,15 +102,15 @@ export class ValidationTypes {
* Checks if validation type is valid.
*/
static isValid(type: string) {
return type !== "isValid" &&
return type !== "isValid" &&
type !== "getMessage" &&
Object.keys(this).map(key => (this as any)[key]).indexOf(type) !== -1;
}

/**
* Gets default validation error message for the given validation type.
*/
static getMessage(type: string, isEach: boolean): string|((args: ValidationArguments) => string) {
static getMessage(type: string, isEach: boolean): string | ((args: ValidationArguments) => string) {
const eachPrefix = isEach ? "each value in " : "";
switch (type) {

Expand All @@ -132,6 +132,8 @@ export class ValidationTypes {
return eachPrefix + "$property must be one of the following values: $constraint1";
case this.IS_NOT_IN:
return eachPrefix + "$property should not be one of the following values: $constraint1";
case this.IS_PORT:
return eachPrefix + "$property must be a port";

/* type checkers */
case this.IS_BOOLEAN:
Expand Down

0 comments on commit 74e568c

Please sign in to comment.