forked from node4good/jest
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alon
committed
Apr 5, 2012
1 parent
5a1f866
commit cd07869
Showing
3 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
Jest | ||
==== | ||
|
||
> JavaScriptational State Stasfer for node.js with easy generating resource from Mongoose ORM | ||
#### # | ||
|
||
introduction | ||
------------ | ||
This module provides: | ||
- Resource base class with: | ||
- Authentication | ||
- Authorization | ||
- Pagination | ||
- Cache | ||
- Throttling | ||
- Validation | ||
- MongooseResource | ||
- Resources listing | ||
|
||
synopsis | ||
-------- | ||
|
||
var express = require('express') | ||
, app = express.createServer(), | ||
, mongoose = require('mongoose') | ||
, Jest = require('jest'); | ||
|
||
var Schema = mongoose.Schema; | ||
|
||
mongoose.connect('mongodb://localhost/app'); | ||
|
||
// create mongoose model | ||
|
||
var User = mongoose.model('user', new Schema({ | ||
username: {type: String, required: true}, | ||
email: String, | ||
password: {type: String, validate: [function(v) { return true}, 'custom validate']}, | ||
credits: {type: Number, min: 1, max: 230}, | ||
role: {type: String, 'default': 'user' ,enum: ['user', 'admin']}, | ||
date: {type:Date, 'default': Date.now}, | ||
groups: [{name:String, permissions: [{name:String, expires:Date}]}] | ||
})); | ||
|
||
// create mongoose resource for User model | ||
|
||
var UserResource = Jest.MongooseResource.extend({ | ||
init: function(){ | ||
// call Jest.Resource constructor | ||
// passing the Model User we created | ||
this._super(User); | ||
|
||
// use array to decide which fields will be visible by API | ||
// this.fields = ['username','credits']; | ||
// use tree object to decide recursively which fields to expose | ||
this.fields = {'username': true, 'credits': true, groups: {name: true, permissions: {name: true} }}; | ||
|
||
// use list or | ||
this.update_fields = ['email', 'password']; | ||
|
||
// specify base query for the model | ||
this.default_query = function(query){ | ||
return query.where('credits').gte(10); | ||
}; | ||
|
||
// specify which fields can be used to filter | ||
this.filtering = {'credits': true}; | ||
|
||
// which http methods are allowed | ||
this.allowed_methods = ['get', 'post', 'put']; | ||
} | ||
}) | ||
|
||
var api = new Jest.Api('api', app); | ||
|
||
api.register('users', new UserResource()); | ||
|
||
installation | ||
------------ | ||
|
||
$ npm install jest | ||
|
||
documentation | ||
------------- | ||
|
||
There is none. | ||
But there is an example, and a test. | ||
|
||
And maybe one day will be... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters