@@ -10,6 +10,7 @@ import { AuthorizationRequiredError } from './error/AuthorizationRequiredError';
1010import { CurrentUserCheckerNotDefinedError } from './error/CurrentUserCheckerNotDefinedError' ;
1111import { isPromiseLike } from './util/isPromiseLike' ;
1212import { InvalidParamError } from './error/ParamNormalizationError' ;
13+ import { ParamType } from "./metadata/types/ParamType" ;
1314
1415/**
1516 * Handles action parameter.
@@ -96,11 +97,12 @@ export class ActionParameterHandler<T extends BaseDriver> {
9697 protected async normalizeParamValue ( value : any , param : ParamMetadata ) : Promise < any > {
9798 if ( value === null || value === undefined ) return value ;
9899
100+ const isNormalisationNeeded = typeof value === 'object' && [ 'queries' , 'headers' , 'params' , 'cookies' ] . some ( paramType => paramType === param . type ) ;
101+ const isTargetPrimitive = [ 'number' , 'string' , 'boolean' ] . indexOf ( param . targetName ) > - 1 ;
102+ const isTransformationNeeded = ( param . parse || param . isTargetObject ) && param . type !== 'param' ;
103+
99104 // if param value is an object and param type match, normalize its string properties
100- if (
101- typeof value === 'object' &&
102- [ 'queries' , 'headers' , 'params' , 'cookies' ] . some ( paramType => paramType === param . type )
103- ) {
105+ if ( isNormalisationNeeded ) {
104106 await Promise . all (
105107 Object . keys ( value ) . map ( async key => {
106108 const keyValue = value [ key ] ;
@@ -123,6 +125,7 @@ export class ActionParameterHandler<T extends BaseDriver> {
123125 } )
124126 ) ;
125127 }
128+
126129 // if value is a string, normalize it to demanded type
127130 else if ( typeof value === 'string' ) {
128131 switch ( param . targetName ) {
@@ -135,7 +138,7 @@ export class ActionParameterHandler<T extends BaseDriver> {
135138 }
136139
137140 // if target type is not primitive, transform and validate it
138- if ( [ 'number' , 'string' , 'boolean' ] . indexOf ( param . targetName ) === - 1 && ( param . parse || param . isTargetObject ) ) {
141+ if ( ! isTargetPrimitive && isTransformationNeeded ) {
139142 value = this . parseValue ( value , param ) ;
140143 value = this . transformValue ( value , param ) ;
141144 value = await this . validateValue ( value , param ) ;
0 commit comments