Provides some convenience functions that can bridge mongoose and your REST endpoints. Nothing special really.
How to get started:
npm install mongoose-rest-helper
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.
mongooseRestHelper = require 'mongoose-rest-helper'
module.exports = class RoleMethods
UPDATE_EXCLUDEFIELDS = ['_id']
constructor:(@model) ->
Return all objects (with pagination, and scoping through accountId)
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
get: (id,options = {}, cb = ->) =>
return cb new Error "id parameter is required." unless id
mongooseRestHelper.getById @model,id,null,options, cb
Destroy an entity
destroy: (id, options = {}, cb = ->) =>
return cb new Error "id parameter is required." unless id
settings = {}
mongooseRestHelper.destroy @model,id, settings,{}, cb
Create an entity
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
patch: (id, obj = {}, options = {}, cb = ->) =>
settings =
exclude : UPDATE_EXCLUDEFIELDS
mongooseRestHelper.patch @model,id, settings, obj, options, cb
- npm install
- grunt watch
- grunt deploy
- hapi-auth-bearer-mw
- hapi-loggly
- hapi-mandrill
- hapi-mongoose-db-connector
- hapi-oauth-store-multi-tenant
- hapi-routes-authorization-and-session-management
- hapi-routes-oauth-management
- hapi-routes-roles
- hapi-routes-status
- hapi-routes-users-authorizations
- hapi-routes-users
- hapi-user-store-multi-tenant
and additionally
- api-pagination
- mongoose-oauth-store-multi-tenant
- mongoose-rest-helper
- mongoose-user-store-multi-tenant
- 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 (c) 2013-2014 Martin Wawrusch See LICENSE for further details.