Skip to content

Commit

Permalink
feat: move get pattern to top level method of switch to ws
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcdo29 committed Nov 9, 2022
1 parent 4bec058 commit 691049c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion integration/websockets/src/request.interceptor.ts
Expand Up @@ -4,7 +4,7 @@ import { CallHandler, ExecutionContext, Injectable } from '@nestjs/common';
export class RequestInterceptor {
intercept(context: ExecutionContext, next: CallHandler) {
const client = context.switchToWs().getClient();
const pattern = client.getPattern();
const pattern = context.switchToWs().getPattern();
client.pattern = pattern;
return next.handle();
}
Expand Down
Expand Up @@ -31,6 +31,10 @@ export interface WsArgumentsHost {
* Returns the client object.
*/
getClient<T = any>(): T;
/**
* Returns the pattern for the event
*/
getPattern(): string;
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/core/helpers/execution-context-host.ts
Expand Up @@ -59,6 +59,7 @@ export class ExecutionContextHost implements ExecutionContext {
return Object.assign(this, {
getClient: () => this.getArgByIndex(0),
getData: () => this.getArgByIndex(1),
getPattern: () => this.getArgByIndex(this.getArgs().length - 1),
});
}
}
4 changes: 1 addition & 3 deletions packages/websockets/context/ws-context-creator.ts
Expand Up @@ -108,9 +108,7 @@ export class WsContextCreator {
};

return this.wsProxy.create(async (...args: unknown[]) => {
Object.assign(args[0] ?? {}, {
getPattern: () => this.reflectCallbackPattern(callback),
});
args.push(this.reflectCallbackPattern(callback));
const initialArgs = this.contextUtils.createNullArray(argsLength);
fnCanActivate && (await fnCanActivate(args));

Expand Down

0 comments on commit 691049c

Please sign in to comment.