Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom decorators require "data" parameter, but built in can skip it #892

Closed
triadium opened this issue Jul 18, 2018 · 5 comments
Closed

Comments

@triadium
Copy link

I'm submitting a...


[ ] Regression 
[ x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

 @Post('register')
  register(@IP() ip: string, @Box('', new QueryValidationPipe(josUserRegisterStep1)) box: IDtoUserRegisterStep1)

Without first argument '' pipe does not work.

Expected behavior

 @Post('register')
  register(@IP() ip: string, @Box(new QueryValidationPipe(josUserRegisterStep1)) box: IDtoUserRegisterStep1)

Minimal reproduction of the problem with instructions

export const Box = createParamDecorator((data, request) => {
  return request.body.box;
});

export const IP = createParamDecorator((data, request) => {
    return request.ip;
});

@Injectable()
export class QueryValidationPipe implements PipeTransform {
  constructor() {}

  transform(value: any, metadata: ArgumentMetadata) {
    console.log('Called');
     return value;
  }
}

@Controller('user')
export class UserApiController {
  @Post('register')
  register(@IP() ip: string, @Box(new QueryValidationPipe()) box: any) {}
}

// curl -X POST http://localhost:3000/user/register

// console.log does not show "Called"

Environment


Nest version: 5.1.0


- Node version: 8.9.3  
- Platform:  Windows 


@autaut03
Copy link
Contributor

Imho, data parameter shouldn't exist. You can just wrap the decorator into another arrow function - this gives a lot more control and is a lot easier to maintain.

@kamilmysliwiec
Copy link
Member

Thanks for reporting, will take a look 🙂

@kamilmysliwiec
Copy link
Member

Fixed #906

@kamilmysliwiec
Copy link
Member

5.2.0 is here!

@lock
Copy link

lock bot commented Sep 24, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants