1.0.1 • Published 7 years ago

mongoose-rest-router v1.0.1

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
7 years ago

mongoose-rest-router

Build Status

Install

npm install --save mongoose-rest-router

Usage example

const mongoose = require('mongoose');

var TestSchema = new mongoose.Schema({
    user: { 
        type: String,
    },
    text: { 
        type: String,
    },
});
var TestModel = mongoose.model('TestModel', TestSchema);
const MongooseRest = require('mongoose-rest-router');
var app = express();

MongooseRest.route(app, TestModel, {
    modelAuth: {
        user: {
            auth_view: true,
            auth_edit: true
        },
        text: {
            auth_view: true,
            auth_edit: function(req){ return req.user === 'admin' }
        },
    },

    preAll: [
        function(req, res, next){
            req.user = req.query.user;
            next();
        }
    ],

    preList: [

    ],

    preGet: [

    ],
    
    preCreate: [
        
    ],

    preUpdate: [

    ],
    
    preDelete: [

    ]

});