1
+ import { MessageArguments } from "./MessageArguments" ;
1
2
/**
2
3
* Validation types.
3
4
*/
@@ -94,14 +95,14 @@ export class ValidationTypes {
94
95
/**
95
96
* Gets default validation error message for the given validation type.
96
97
*/
97
- static getMessage ( type : string ) : string | ( ( value ?: any , constraints ?: any [ ] ) => string ) {
98
+ static getMessage ( type : string ) : string | ( ( args : MessageArguments ) => string ) {
98
99
switch ( type ) {
99
100
100
101
/* common checkers */
101
102
case this . EQUALS :
102
- return "given value ($value) of $ property is not equal to $constraint1" ;
103
+ return "$ property must be equal to $constraint1" ;
103
104
case this . NOT_EQUALS :
104
- return "given value ($value) of $property should not be equal to $constraint1" ;
105
+ return "$property should not be equal to $constraint1" ;
105
106
case this . EMPTY :
106
107
return "$property must be empty" ;
107
108
case this . NOT_EMPTY :
@@ -130,6 +131,8 @@ export class ValidationTypes {
130
131
return "$property must be divisible by $constraint1" ;
131
132
case this . IS_POSITIVE :
132
133
return "$property must be a positive number" ;
134
+ case this . IS_NEGATIVE :
135
+ return "$property must be a negative number" ;
133
136
case this . GREATER_THEN :
134
137
return "$property must be greater then $constraint1" ;
135
138
case this . LESS_THEN :
@@ -147,7 +150,7 @@ export class ValidationTypes {
147
150
case this . IS_DATE_STRING :
148
151
return "$property must be a date string" ;
149
152
case this . IS_NUMBER_STRING :
150
- return "$property must be a number" ;
153
+ return "$property must be a number string " ;
151
154
152
155
/* string checkers */
153
156
case this . CONTAINS :
@@ -209,15 +212,22 @@ export class ValidationTypes {
209
212
case this . IS_UPPERCASE :
210
213
return "$property must be uppercase" ;
211
214
case this . LENGTH :
212
- return ( ) => { // todo
215
+ return ( args : MessageArguments ) => { // todo more complex object must come here (with target and propertyName)
216
+ const isMinLength = args . constraints [ 0 ] !== null && args . constraints [ 0 ] !== undefined ;
217
+ const isMaxLength = args . constraints [ 1 ] !== null && args . constraints [ 1 ] !== undefined ;
218
+ if ( isMinLength && ( ! args . value || args . value . length < args . constraints [ 0 ] ) ) {
219
+ return "$property must be longer then $constraint1" ;
220
+ } else if ( isMaxLength && ( args . value . length > args . constraints [ 1 ] ) ) {
221
+ return "$property must be shorter then $constraint2" ;
222
+ }
213
223
return "$property must be longer then $constraint1 and shorter then $constraint2" ;
214
224
} ;
215
225
case this . MIN_LENGTH :
216
226
return "$property must be longer then $constraint1" ;
217
227
case this . MAX_LENGTH :
218
228
return "$property must be shorter then $constraint2" ;
219
229
case this . MATCHES :
220
- return "$property must much a given regular expression $constraint1 " ;
230
+ return "$property must match $constraint1 regular expression" ;
221
231
222
232
/* array checkers */
223
233
case this . ARRAY_CONTAINS :
@@ -227,11 +237,11 @@ export class ValidationTypes {
227
237
case this . ARRAY_NOT_EMPTY :
228
238
return "$property should not be empty" ;
229
239
case this . ARRAY_MIN_SIZE :
230
- return "$property's must contain at least $constraint1 elements" ;
240
+ return "$property must contain at least $constraint1 elements" ;
231
241
case this . ARRAY_MAX_SIZE :
232
- return "$property's must contain not more then $constraint1 elements" ;
242
+ return "$property must contain not more then $constraint1 elements" ;
233
243
case this . ARRAY_UNIQUE :
234
- return "all $property's elements must be unqiue " ;
244
+ return "All $property's elements must be unique " ;
235
245
}
236
246
}
237
247
0 commit comments