1.0.5 • Published 7 years ago
controller-factory v1.0.5
Controller (middleware) factory product instances of which provide basic api for handling CRUD requests.
Using this component provides flexibility of creating very common in most cases Express routes middlewares. It helps to avoid code duplication and keep you code DRY and in the same time customize controllers when needed.
import ControllerFactory from 'controller-factory' import Entity from './model'
const controller = ControllerFactory.getControllerFor(Entity) const entityRoutes = express.Router()
entityRoutes .post('/', controller.create) .get('/', controller.find) .get('/:id', controller.findById) .put('/:id', controller.update) .delete('/:id', controller.remove)
<h2>API</h2>
`ControllerFactory.getControllerFor(entity, overrides, base)`
Parameters:
`entity <Object>` Mongoose model instance, required
`overrides <Object>` Mixin containing CRUD methods to override base ones, default plain object
`base <Object>` Base object containing CRUD methods, default ControllerBase
Please find base implementation in [./lib/controller-base.js](https://github.com/ygrishajev/controller-factory/blob/master/lib/controller-base.js)