Passing validation DTO as generic to a parent class. Nest.js

Viewed 527

I have a base class CRUD implementation that looks like this:

abstract class BaseController<T extends BaseEntity, E> {
 constructor(private readonly IBaseService: IBaseService<T, E>) {}

 @Post()
 @ApiResponse({
   status: 201,
   description: 'The record has been successfully created.',
 })
 @ApiResponse({ status: 403, description: 'Forbidden.' })
 @ApiResponse({ status: 400, description: 'Bad Request.' })
 @SetMetadata('code', `WRITE`)
 async create(@Body() entity: E): Promise<E> {
   return this.IBaseService.create(entity)
 }
}

and a class of the provider controller that extends the base class for CRUD methods:

@ApiTags('providers')
@Controller('providers')
@SetMetadata('code', 'PROVIDER')
@UseGuards(JwtAuthGuard)
export class ProviderController extends BaseController<Providers, ProviderDto> {
  constructor(private readonly providersService: ProvidersService) {
    super(providersService)
  }
}

I need to pass the ProviderDto to the parent class BaseController to validate the create method with ValidationPipe. But for some reason it doesn't work this way. Maybe my approach is incorrect?

0 Answers
Related