controller-factory
v1.0.5
Published
Express-Mongoose Controller Factory
Maintainers
Readme
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.
npm install controller-factory
import express from 'express'
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)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
