@nestjs/common#ContextType TypeScript Examples

The following examples show how to use @nestjs/common#ContextType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: create-execution-context.ts    From google-recaptcha with MIT License 5 votes vote down vote up
export function createExecutionContext(handler: Function, req: Partial<Request>): ExecutionContext {
    return new class implements ExecutionContext {
        getHandler(): Function {
            return handler;
        }

        switchToHttp(): HttpArgumentsHost {
            return createArgumentHost(req);
        }

        getArgByIndex<T = any>(index: number): T {
            console.error('Method \'getArgByIndex\' doesn\'t implemented');
            return undefined;
        }

        getArgs<T = any[]>(): T {
            console.error('Method \'getArgs\' doesn\'t implemented');
            return undefined;
        }

        getClass<T = any>(): Type<T> {
            console.error('Method \'getClass\' doesn\'t implemented');
            return undefined;
        }

        getType<TContext = ContextType>(): TContext {
            return 'http' as any;
        }

        switchToRpc(): RpcArgumentsHost {
            console.error('Method \'switchToRpc\' doesn\'t implemented');
            return undefined;
        }

        switchToWs(): WsArgumentsHost {
            console.error('Method \'switchToWs\' doesn\'t implemented');
            return undefined;
        }
    }
}