File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -65,8 +65,10 @@ export class ValidationPipe implements PipeTransform<any> {
6565 if ( ! metatype || ! this . toValidate ( metadata ) ) {
6666 return value ;
6767 }
68+ const originalValue = value ;
6869 value = this . toEmptyIfNil ( value ) ;
6970
71+ const isNil = value !== originalValue ;
7072 const isPrimitive = this . isPrimitive ( value ) ;
7173 this . stripProtoKeys ( value ) ;
7274 let entity = classTransformer . plainToClass (
@@ -96,9 +98,14 @@ export class ValidationPipe implements PipeTransform<any> {
9698 // we have to revert the original value passed through the pipe
9799 entity = originalEntity ;
98100 }
99- return this . isTransformEnabled
100- ? entity
101- : Object . keys ( this . validatorOptions ) . length > 0
101+ if ( this . isTransformEnabled ) {
102+ return entity ;
103+ }
104+ if ( isNil ) {
105+ // if the value was originally undefined or null, revert it back
106+ return originalValue ;
107+ }
108+ return Object . keys ( this . validatorOptions ) . length > 0
102109 ? classTransformer . classToPlain ( entity , this . transformOptions )
103110 : value ;
104111 }
You can’t perform that action at this time.
0 commit comments