fix(core) dont wait non-pipeable params

This commit is contained in:
Kamil Myśliwiec
2019-10-10 13:25:41 +02:00
parent afbacbf48a
commit a5049e770f
2 changed files with 29 additions and 20 deletions

View File

@@ -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,
@@ -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,
@@ -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));
};

View File

@@ -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;
});
});
});