Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ehasa-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WIMMA Lab 2019
Overflow
ehasa-backend
Commits
54dd811e
Commit
54dd811e
authored
5 years ago
by
Ronnie Friman
Browse files
Options
Downloads
Patches
Plain Diff
added nested validation errors
parent
70993d76
No related branches found
Branches containing commit
No related tags found
3 merge requests
!59
Development to master
,
!31
Development
,
!29
Json validation
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/shared/validation.pipe.ts
+11
-3
11 additions, 3 deletions
src/shared/validation.pipe.ts
with
11 additions
and
3 deletions
src/shared/validation.pipe.ts
+
11
−
3
View file @
54dd811e
...
@@ -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
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment