# controller-factory

> Express-Mongoose Controller Factory

Latest version **1.0.5** (published 2017-03-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install controller-factory
pnpm add controller-factory
yarn add controller-factory
bun add controller-factory
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2017-03-20 |
| First published | 2017-03-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+8 in 1 direct dependencies) |
| Install scripts | no |
| Author | Yaroslav Grishajev |
| Maintainers | ygrishajev |
| Keywords | middleware, controller, mongoose, express, node, mongoDB |

## Links

- npm: https://www.npmjs.com/package/controller-factory
- Repository: https://github.com/ygrishajev/controller-factory
- Homepage: https://github.com/ygrishajev/controller-factory#readme
- Issues: https://github.com/ygrishajev/controller-factory/issues
- npm.io page: https://npm.io/package/controller-factory

## Dependencies (3)

- [express](https://npm.io/package/express.md) ^4.14.0
- [mongoose](https://npm.io/package/mongoose.md) 4.7.2
- [body-parser](https://npm.io/package/body-parser.md) ^1.15.2

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.0.5 (latest) — 2017-03-20
- 1.0.4 — 2017-03-20
- 1.0.3 — 2017-03-19
- 1.0.2 — 2017-03-18
- 1.0.1 — 2017-03-18

## README

<h1>Express-Mongoose Controller Factory</h1>

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.

<h2>Installation</h2>
  
`npm install controller-factory`

<h2>Usage Example</h2>
  
```
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)
```

<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)

---
_Source: https://npm.io/package/controller-factory · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
