Skip to content
Snippets Groups Projects
Commit 54dd811e authored by Ronnie Friman's avatar Ronnie Friman
Browse files

added nested validation errors

parent 70993d76
No related branches found
No related tags found
3 merge requests!59Development to master,!31Development,!29Json validation
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
} from '@nestjs/common'; } from '@nestjs/common';
import { validate } from 'class-validator'; import { validate } from 'class-validator';
import { plainToClass } from 'class-transformer'; import { plainToClass } from 'class-transformer';
import { AdvancedConsoleLogger } from 'typeorm';
@Injectable() @Injectable()
export class ValidationPipe implements PipeTransform<any> { export class ValidationPipe implements PipeTransform<any> {
...@@ -44,13 +45,20 @@ export class ValidationPipe implements PipeTransform<any> { ...@@ -44,13 +45,20 @@ export class ValidationPipe implements PipeTransform<any> {
private formatErrors(errors: any[]) { private formatErrors(errors: any[]) {
return errors return errors
.map(err => { .map(err => {
for (let property in err.constraints) { return this.returnError(err);
return err.constraints[property];
}
}) })
.join(', '); .join(', ');
} }
private returnError(err) {
if (err['children'] !== undefined && err['children'].length != 0) {
return this.formatErrors(err['children']);
}
for (let property in err.constraints) {
return err.constraints[property];
}
}
private isEmpty(value: any) { private isEmpty(value: any) {
return Object.keys(value).length > 0 ? false : true; return Object.keys(value).length > 0 ? false : true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment