# mongoose-rest-helper

> A bunch of helpers used to simplify rest development.

Latest version **2.0.2** (published 2015-11-25) · 0 weekly downloads

## Install

```sh
npm install mongoose-rest-helper
pnpm add mongoose-rest-helper
yarn add mongoose-rest-helper
bun add mongoose-rest-helper
```

## 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 | 2.0.2 |
| Published | 2015-11-25 |
| First published | 2013-12-08 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.8.0 |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Martin Wawrusch |
| Maintainers | mwawrusch |
| Keywords | mongoose |

## Links

- npm: https://www.npmjs.com/package/mongoose-rest-helper
- Repository: https://github.com/codedoctor/mongoose-rest-helper
- Issues: http://github.com/codedoctor/mongoose-rest-helper/issues
- npm.io page: https://npm.io/package/mongoose-rest-helper

## Dependencies (3)

- [hoek](https://npm.io/package/hoek.md) 2.14.0
- [underscore](https://npm.io/package/underscore.md) 1.8.3
- [mongodb-objectid-helper](https://npm.io/package/mongodb-objectid-helper.md) 0.2.0

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

- 2.0.2 (latest) — 2015-11-25
- 2.0.1 — 2015-08-17
- 1.1.1 — 2014-12-20
- 1.0.3 — 2014-12-20
- 1.0.2 — 2014-08-12
- 1.0.1 — 2014-08-12
- 0.1.7 — 2013-12-09
- 0.1.6 — 2013-12-09
- 0.1.5 — 2013-12-09
- 0.1.4 — 2013-12-09
- 0.1.3 — 2013-12-09
- 0.1.2 — 2013-12-08
- 0.1.1 — 2013-12-08

## README

[![Build Status](https://travis-ci.org/codedoctor/mongoose-rest-helper.svg?branch=master)](https://travis-ci.org/codedoctor/mongoose-rest-helper)
[![Coverage Status](https://img.shields.io/coveralls/codedoctor/mongoose-rest-helper.svg)](https://coveralls.io/r/codedoctor/mongoose-rest-helper)
[![NPM Version](http://img.shields.io/npm/v/mongoose-rest-helper.svg)](https://www.npmjs.org/package//mongoose-rest-helper)
[![Dependency Status](https://gemnasium.com/codedoctor/mongoose-rest-helper.svg)](https://gemnasium.com/codedoctor/mongoose-rest-helper)
[![NPM Downloads](http://img.shields.io/npm/dm/mongoose-rest-helper.svg)](https://www.npmjs.org/package/mongoose-rest-helper)
[![Issues](http://img.shields.io/github/issues/codedoctor/mongoose-rest-helper.svg)](https://github.com/codedoctor/mongoose-rest-helper/issues)
[![API Documentation](http://img.shields.io/badge/API-Documentation-ff69b4.svg)](http://coffeedoc.info/github/codedoctor/mongoose-rest-helper)

## mongoose-rest-helper

Provides some convenience functions that can bridge mongoose and your REST endpoints. Nothing special really.

How to get started:

npm install mongoose-rest-helper

## Usage

The following illustrates a typical use case where we map CRUD functions
to the mongoose-rest-helper. This is verbose, you could easily create this
for all your models. 

```coffeescript

mongooseRestHelper = require 'mongoose-rest-helper'

module.exports = class RoleMethods
  UPDATE_EXCLUDEFIELDS = ['_id']

  constructor:(@model) ->
```
Return all objects (with pagination, and scoping through accountId)
```coffeescript
  all: (accountId,options = {},cb = ->) =>
    return cb new Error "accountId parameter is required." unless accountId

    settings = 
        baseQuery:
          accountId : mongooseRestHelper.asObjectId accountId
        defaultSort: 'name'
        defaultSelect: null
        defaultCount: 1000
    mongooseRestHelper.all @model,settings,options, cb

```
Get an entity for it's id
```coffeescript
  get: (id,options = {}, cb = ->) =>
    return cb new Error "id parameter is required." unless id
    mongooseRestHelper.getById @model,id,null,options, cb

```
Destroy an entity
```coffeescript
  destroy: (id, options = {}, cb = ->) =>
    return cb new Error "id parameter is required." unless id
    settings = {}
    mongooseRestHelper.destroy @model,id, settings,{}, cb

```
Create an entity
```coffeescript
  create:(accountId,objs = {}, options = {}, cb = ->) =>
    return cb new Error "accountId parameter is required." unless accountId
    settings = {}
    objs.accountId = mongooseRestHelper.asObjectId accountId
    mongooseRestHelper.create @model,settings,objs,options,cb

```
Update an entity
```coffeescript
  patch: (id, obj = {}, options = {}, cb = ->) =>
    settings =
      exclude : UPDATE_EXCLUDEFIELDS
    mongooseRestHelper.patch @model,id, settings, obj, options, cb
```

## Stuff

* npm install
* grunt watch
* grunt deploy

## See also

* [hapi-auth-bearer-mw](https://github.com/codedoctor/hapi-auth-bearer-mw)
* [hapi-loggly](https://github.com/codedoctor/hapi-loggly)
* [hapi-mandrill](https://github.com/codedoctor/hapi-mandrill)
* [hapi-mongoose-db-connector](https://github.com/codedoctor/hapi-mongoose-db-connector)
* [hapi-oauth-store-multi-tenant](https://github.com/codedoctor/hapi-oauth-store-multi-tenant)
* [hapi-routes-authorization-and-session-management](https://github.com/codedoctor/hapi-routes-authorization-and-session-management)
* [hapi-routes-oauth-management](https://github.com/codedoctor/hapi-routes-oauth-management)
* [hapi-routes-roles](https://github.com/codedoctor/hapi-routes-roles)
* [hapi-routes-status](https://github.com/codedoctor/hapi-routes-status)
* [hapi-routes-users-authorizations](https://github.com/codedoctor/hapi-routes-users-authorizations)
* [hapi-routes-users](https://github.com/codedoctor/hapi-routes-users)
* [hapi-user-store-multi-tenant](https://github.com/codedoctor/hapi-user-store-multi-tenant)

and additionally

* [api-pagination](https://github.com/codedoctor/api-pagination)
* [mongoose-oauth-store-multi-tenant](https://github.com/codedoctor/mongoose-oauth-store-multi-tenant)
* [mongoose-rest-helper](https://github.com/codedoctor/mongoose-rest-helper)
* [mongoose-user-store-multi-tenant](https://github.com/codedoctor/mongoose-user-store-multi-tenant)


## Contributing to mongoose-rest-helper
 
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
* Fork the project
* Start a feature/bugfix branch
* Commit and push until you are happy with your contribution
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
* Please try not to mess with the package.json, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

## Copyright

Copyright (c) 2013-2014 Martin Wawrusch See LICENSE for
further details.

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