@@ -10,6 +10,7 @@ import { AuthorizationRequiredError } from './error/AuthorizationRequiredError';
10
10
import { CurrentUserCheckerNotDefinedError } from './error/CurrentUserCheckerNotDefinedError' ;
11
11
import { isPromiseLike } from './util/isPromiseLike' ;
12
12
import { InvalidParamError } from './error/ParamNormalizationError' ;
13
+ import { ParamType } from "./metadata/types/ParamType" ;
13
14
14
15
/**
15
16
* Handles action parameter.
@@ -96,11 +97,12 @@ export class ActionParameterHandler<T extends BaseDriver> {
96
97
protected async normalizeParamValue ( value : any , param : ParamMetadata ) : Promise < any > {
97
98
if ( value === null || value === undefined ) return value ;
98
99
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
+
99
104
// 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 ) {
104
106
await Promise . all (
105
107
Object . keys ( value ) . map ( async key => {
106
108
const keyValue = value [ key ] ;
@@ -123,6 +125,7 @@ export class ActionParameterHandler<T extends BaseDriver> {
123
125
} )
124
126
) ;
125
127
}
128
+
126
129
// if value is a string, normalize it to demanded type
127
130
else if ( typeof value === 'string' ) {
128
131
switch ( param . targetName ) {
@@ -135,7 +138,7 @@ export class ActionParameterHandler<T extends BaseDriver> {
135
138
}
136
139
137
140
// 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 ) {
139
142
value = this . parseValue ( value , param ) ;
140
143
value = this . transformValue ( value , param ) ;
141
144
value = await this . validateValue ( value , param ) ;
0 commit comments