Skip to content

Commit a5049e7

Browse files
fix(core) dont wait non-pipeable params
1 parent afbacbf commit a5049e7

2 files changed

Lines changed: 29 additions & 20 deletions

File tree

packages/core/router/router-execution-context.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,7 @@ export class RouterExecutionContext {
301301
}: { metatype: unknown; type: RouteParamtypes; data: unknown },
302302
pipes: PipeTransform[],
303303
): Promise<unknown> {
304-
if (
305-
(type === RouteParamtypes.BODY ||
306-
type === RouteParamtypes.QUERY ||
307-
type === RouteParamtypes.PARAM ||
308-
isString(type)) &&
309-
!isEmpty(pipes)
310-
) {
304+
if (!isEmpty(pipes)) {
311305
return this.pipesConsumer.apply(
312306
value,
313307
{ metatype, type, data } as any,
@@ -317,6 +311,15 @@ export class RouterExecutionContext {
317311
return value;
318312
}
319313

314+
public isPipeable(type: number | string): boolean {
315+
return (
316+
type === RouteParamtypes.BODY ||
317+
type === RouteParamtypes.QUERY ||
318+
type === RouteParamtypes.PARAM ||
319+
isString(type)
320+
);
321+
}
322+
320323
public createGuardsFn<TContext extends ContextType = ContextType>(
321324
guards: any[],
322325
instance: Controller,
@@ -361,11 +364,13 @@ export class RouterExecutionContext {
361364
} = param;
362365
const value = extractValue(req, res, next);
363366

364-
args[index] = await this.getParamValue(
365-
value,
366-
{ metatype, type, data } as any,
367-
pipes.concat(paramPipes),
368-
);
367+
args[index] = this.isPipeable(type)
368+
? await this.getParamValue(
369+
value,
370+
{ metatype, type, data } as any,
371+
pipes.concat(paramPipes),
372+
)
373+
: value;
369374
};
370375
await Promise.all(paramsOptions.map(resolveParamValue));
371376
};

packages/core/test/router/router-execution-context.spec.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,18 @@ describe('RouterExecutionContext', () => {
258258
).to.be.true;
259259
});
260260
});
261-
describe('when paramtype is not query, body and param', () => {
262-
it('should not call "consumer.apply"', () => {
263-
contextCreator.getParamValue(
264-
value,
265-
{ metatype, type: RouteParamtypes.NEXT, data: null },
266-
transforms,
267-
);
268-
expect(consumerApplySpy.called).to.be.false;
261+
});
262+
describe('isPipeable', () => {
263+
describe('when paramtype is not query, body, param and custom', () => {
264+
it('should return false', () => {
265+
const result = contextCreator.isPipeable(RouteParamtypes.NEXT);
266+
expect(result).to.be.false;
267+
});
268+
it('otherwise', () => {
269+
expect(contextCreator.isPipeable(RouteParamtypes.BODY)).to.be.true;
270+
expect(contextCreator.isPipeable(RouteParamtypes.QUERY)).to.be.true;
271+
expect(contextCreator.isPipeable(RouteParamtypes.PARAM)).to.be.true;
272+
expect(contextCreator.isPipeable('custom')).to.be.true;
269273
});
270274
});
271275
});

0 commit comments

Comments
 (0)