herbsjs / herbs2rest

Create a REST API based on HerbsJS
MIT License
2 stars 13 forks source link

Override the default controller #12

Closed dalssoft closed 3 years ago

dalssoft commented 3 years ago

Having a internal default controller is useful but forcing it is bad. There should be a way to override the default controller for certain use cases.

Suggested UX:

const myController = async (usecase, req, user, res, next, methodName) => {
...
}

const controllerList = [
  {
    name: 'lists',
    idParameter: 'listId',
    getAll: require('../usecases/getLists'), // default internal controller
    getById: { usecase: require('../usecases/getLists'), controller: myController }, // my controller
    ...
  }
]
gabrielmellooliveira commented 3 years ago

I created the customization for the controller and the addition of the name of the customized route parameter.

PR - https://github.com/herbsjs/herbs2rest/pull/11

dalssoft commented 3 years ago

great! tks!!