Simon Rechermann
Simon Rechermann

Reputation: 501

NestJSX get parameter from CrudRequest object

I want to overrride the following route which was generated by nestjsx:

GET /offer-event-matchings/{id}

To get the id from the CrudRequest I wrote the following code.

  @Override()
  getOne(@ParsedRequest() req: CrudRequest): Promise<GetUserDto> {
    const id = req.parsed.search.$and[1]['id']['$eq'];
    return this.service.getOfferEventMatching(id);
  }

It works but I think and hope there is a better and more beautiful way to get the id from the CrudRequest object?

Upvotes: 3

Views: 1160

Answers (1)

mouche
mouche

Reputation: 1903

The bottom of the section Routes Override in the docs mentions you can use the typical decorators as well, so the easiest would be to use Param:

getOne(
  @ParsedRequest() req: CrudRequest,
  @Param('id') id: string
): Promise<GetUserDto> {
  // code here
}

Upvotes: 3

Related Questions