nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.83k stars 7.65k forks source link

[Request] @Inject(REQUEST) on constructor of provide APP_PIPE #2193

Closed zinzinday closed 5 years ago

zinzinday commented 5 years ago

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

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.

Environment


Nest version: 6.2.0
kamilmysliwiec commented 5 years ago

See https://github.com/nestjs/nest/issues/1916

lock[bot] commented 5 years ago

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.