Skip to content

Commit

Permalink
fix(core) dont wait non-pipeable params
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Oct 10, 2019
1 parent afbacbf commit a5049e7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
29 changes: 17 additions & 12 deletions packages/core/router/router-execution-context.ts
Expand Up @@ -301,13 +301,7 @@ export class RouterExecutionContext {
}: { metatype: unknown; type: RouteParamtypes; data: unknown },
pipes: PipeTransform[],
): Promise<unknown> {
if (
(type === RouteParamtypes.BODY ||
type === RouteParamtypes.QUERY ||
type === RouteParamtypes.PARAM ||
isString(type)) &&
!isEmpty(pipes)
) {
if (!isEmpty(pipes)) {
return this.pipesConsumer.apply(
value,
{ metatype, type, data } as any,
Expand All @@ -317,6 +311,15 @@ export class RouterExecutionContext {
return value;
}

public isPipeable(type: number | string): boolean {
return (
type === RouteParamtypes.BODY ||
type === RouteParamtypes.QUERY ||
type === RouteParamtypes.PARAM ||
isString(type)
);
}

public createGuardsFn<TContext extends ContextType = ContextType>(
guards: any[],
instance: Controller,
Expand Down Expand Up @@ -361,11 +364,13 @@ export class RouterExecutionContext {
} = param;
const value = extractValue(req, res, next);

args[index] = await this.getParamValue(
value,
{ metatype, type, data } as any,
pipes.concat(paramPipes),
);
args[index] = this.isPipeable(type)
? await this.getParamValue(
value,
{ metatype, type, data } as any,
pipes.concat(paramPipes),
)
: value;
};
await Promise.all(paramsOptions.map(resolveParamValue));
};
Expand Down
20 changes: 12 additions & 8 deletions packages/core/test/router/router-execution-context.spec.ts
Expand Up @@ -258,14 +258,18 @@ describe('RouterExecutionContext', () => {
).to.be.true;
});
});
describe('when paramtype is not query, body and param', () => {
it('should not call "consumer.apply"', () => {
contextCreator.getParamValue(
value,
{ metatype, type: RouteParamtypes.NEXT, data: null },
transforms,
);
expect(consumerApplySpy.called).to.be.false;
});
describe('isPipeable', () => {
describe('when paramtype is not query, body, param and custom', () => {
it('should return false', () => {
const result = contextCreator.isPipeable(RouteParamtypes.NEXT);
expect(result).to.be.false;
});
it('otherwise', () => {
expect(contextCreator.isPipeable(RouteParamtypes.BODY)).to.be.true;
expect(contextCreator.isPipeable(RouteParamtypes.QUERY)).to.be.true;
expect(contextCreator.isPipeable(RouteParamtypes.PARAM)).to.be.true;
expect(contextCreator.isPipeable('custom')).to.be.true;
});
});
});
Expand Down

0 comments on commit a5049e7

Please sign in to comment.