mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
fix(core) dont wait non-pipeable params
This commit is contained in:
@@ -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));
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user