gid-oss / dataui-nestjs-crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
130 stars 31 forks source link

extend CrudController #48

Open its-dibo opened 7 months ago

its-dibo commented 7 months ago

we can implement the interface CrudController<Entity>, is there a way to provide a class that extends CrudController instead of the original one?

CrudConfigService.load({
CrudController: ExtendedCrudController
})
class ExtendedCrudController extends CrudController{

additionalMethod(req){
  return this.service.something();
}

}

sure we can create a class from scratch that implements CrudController, but in this case we'll need to implement all methods from scratch, unless the class itself is exposed

// suppose that there is a class named CrudControllerClass is exposed by this library
class ExtendedCrudController extends CrudControllerClass{}

// and in the controller
class MyController extends ExtendedCrudController{}
its-dibo commented 7 months ago

as a suggestion, we can extend the decorator @Crud, but I don't think this is the best approach

zaro commented 7 months ago

@its-dibo I am not sure I fully understand your question/request but let me try to answer :)

1st you should note that there is no base controller! The Crud methods are injected by the decorator like you would do a mixin. The relevant code , see here for the implementation https://github.com/gid-oss/dataui-nestjs-crud/blob/master/packages/crud/src/crud/crud-routes.factory.ts#L320 .

So you can extend your controller from whatever base class you want/need, just keep in mind that all the route methods will be overridden by the decorator unless you decorate them with @Override.

Hope that helps!