Closed zinzinday closed 5 years ago
I can not to @Inject(REQUEST) on constructor of provide APP_PIPE useClass I want inject Request Context into PipeTransform to global transform by user account roles
import { ArgumentMetadata, Inject, Injectable, PipeTransform, Scope } from '@nestjs/common'; import { REQUEST } from '@nestjs/core'; @Injectable({ scope: Scope.REQUEST, }) export class TestPipe implements PipeTransform { constructor(@Inject(REQUEST) public request: any) { console.log('constructor', request); } transform(value: any, metadata: ArgumentMetadata) { console.log('transform', this.request); // transform undefined return value; } }
import { Exclude, Expose } from 'class-transformer'; @Exclude() export class TestDto { @Expose({ groups: ['admin'] }) role: string; @Expose({ groups: ['owned'] }) password: string; @Expose() name: string; }
import { Module} from '@nestjs/common'; import { AppController } from './app.controller'; import { APP_PIPE } from '@nestjs/core'; import { TestPipe } from './test.pipe'; @Module({ imports: [], controllers: [AppController], providers: [ { provide: APP_PIPE, useClass: TestPipe, }], }) export class AppModule { }
import { Body, Controller, Get, Param, Put } from '@nestjs/common'; import { TestDto } from './test.dto'; @Controller() export class AppController { @Get() getHello(): string { return 'Hello work'; } @Put(':id') async update(@Param('id') id: string, @Body() data: TestDto) { // todo something console.log(data); return data; } }
same issues #2130 #2032 have been resolved. but this issue have been not resolve. Please resolve thanks advanced.
Nest version: 6.2.0
See https://github.com/nestjs/nest/issues/1916
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Feature Request
I can not to @Inject(REQUEST) on constructor of provide APP_PIPE useClass I want inject Request Context into PipeTransform to global transform by user account roles
same issues #2130 #2032 have been resolved. but this issue have been not resolve. Please resolve thanks advanced.
Environment