2

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.

shyammakwana.me
  • 5,562
  • 2
  • 29
  • 50
  • 1
    I guess you can use simple inheritance, why not? – MorKadosh Sep 10 '20 at 07:15
  • @MorKadosh I have this in mind as last option, I'm just looking if there's any other best practice. – shyammakwana.me Sep 10 '20 at 07:47
  • 2
    Yes. I know that feeling when you think that a solution is too obvious. On the other hand, we are talking about plain classes, nothing more. So it might be that the obvious solution is the best one – MorKadosh Sep 10 '20 at 07:53

1 Answers1

3

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 {}
shyammakwana.me
  • 5,562
  • 2
  • 29
  • 50
  • Same thing happened with me. I was looking for a standard way to do this Nest. Found IntersectionType, but for that, have to create an extra class, so now using simple inheritance :) – heethjain21 Jun 08 '22 at 04:32