Search code examples
node.jsnestjsdtonestjs-swagger

NestJs merging 2 DTOs or best practices


I have one common Dto for Pagination. But while some of the apis need more parameters and pagination too. e.g. search, filter etc. So my method would become like below :

 getAllCelebrities(
        @AuthUser('_id') userId: string,
        @Body() paginationnewDto: PaginationnewDto,
        @Body() getCelebritiesDto: GetCelebritiesDto,
    ) 

Having 2 body params generates 2 blocks in swagger. Like below: enter image description here

Also when I console both params, it returns same object.

What is the best practice for this such that I don't have to put pagination params in my getCelebritiesDto? And I can be DRY.


Solution

  • Answering my own Question as I didn't find any other alternative. As per my thought and @MorKadosh's suggestion here is a simple solution. I've extended PaginationnewDto in GetCelebritiesDto

    export class GetCelebritiesDto extends PaginationnewDto {}