File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -186,6 +186,7 @@ All the templates for the commands are located in `src/console/templates`.
186186* ` npm run console make:request <file> ` - Generates a basic request.
187187* ` npm run console make:listener <file> ` - Generates a basic listener.
188188* ` npm run console make:exception <file> ` - Generates a basic exception.
189+ * ` npm run console make:validator <file> ` - Generates a custom validator.
189190* ` npm run console update:targets <file> ` - Reads all the API files and generate a new ` constants/Targets.ts ` file out of it.
190191
191192** Example**
Original file line number Diff line number Diff line change 1+ /**
2+ * MakeValidatorCommand
3+ * -------------------------------------
4+ *
5+ */
6+ import { AbstractMakeCommand } from './lib/AbstractMakeCommand' ;
7+
8+
9+ export class MakeValidatorCommand extends AbstractMakeCommand {
10+
11+ public static command = 'make:validator' ;
12+ public static description = 'Generate new validator' ;
13+
14+ public type = 'Validator' ;
15+ public suffix = 'Validator' ;
16+ public template = 'validator.hbs' ;
17+ public target = 'api/validators' ;
18+ public updateTargets = false ;
19+
20+ }
Original file line number Diff line number Diff line change 1+ import { ValidatorConstraint, ValidatorConstraintInterface, ValidationArguments } from 'class-validator';
2+
3+
4+ @ValidatorConstraint({ name: '{{ name.normal }} ', async: false })
5+ export class {{ name.capitalize }} Validator implements ValidatorConstraintInterface {
6+
7+ public validate(text: string, args: ValidationArguments): boolean {
8+ // Place your validation here
9+ return true;
10+ }
11+
12+ public defaultMessage(args: ValidationArguments): string {
13+ // Error message if the validation fails
14+ return 'Incorrect value';
15+ }
16+
17+ }
You can’t perform that action at this time.
0 commit comments