'Can I write a DTO which extracts both query and params vars in nestjs
I'm making an api which looks like:
http://example.com/story/:storyId/analytics?from={date}&to={date}
The storyId is part of the path, but from and to are query parameters.
I've got a DTO, like this:
class GetStoryAnalyticsDTO {
storyId: string
from: Date
to: Date
}
(validators omitted for brevity)
And I'm using it like this in my controler:
@Get()
getStoryAnalytics(@Query() query: GetStoryAnalyticsRequestDto): Promise<MyResponse> {...}
But, (obviously!), this only extracts the from and to parameters.
Is there any way to extract both from the query and the path to get all the vars in one dto?
If not, it's not a massive hassle - I can just add @Param storyId: string to the controller and it's all good :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
