diff options
Diffstat (limited to 'common/src/main/webapp/usageguide/appserver/node_modules/node-restful/examples/notes/models')
3 files changed, 52 insertions, 0 deletions
diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/node-restful/examples/notes/models/index.js b/common/src/main/webapp/usageguide/appserver/node_modules/node-restful/examples/notes/models/index.js new file mode 100644 index 0000000..203375e --- /dev/null +++ b/common/src/main/webapp/usageguide/appserver/node_modules/node-restful/examples/notes/models/index.js @@ -0,0 +1,11 @@ +var User = require('./user'), + Notes = require('./note'), + userroutes = require('../routes/user'); + +console.log(userroutes); +for (var route in userroutes) { + User.userroute(route, userroutes[route]); +} + +exports = module.exports = [User, Notes]; + diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/node-restful/examples/notes/models/note.js b/common/src/main/webapp/usageguide/appserver/node_modules/node-restful/examples/notes/models/note.js new file mode 100644 index 0000000..b62861a --- /dev/null +++ b/common/src/main/webapp/usageguide/appserver/node_modules/node-restful/examples/notes/models/note.js @@ -0,0 +1,28 @@ +var restful = require('../../../'), + mongoose = require('mongoose'), + User = require('./user'); + +var validateUser = function(req, res, next) { + console.log("Add User"); + if (req.body.creator) { + User.Obj.findById(req.body.creator, function(err, model) { + if (!model) { + return next(restful.objectNotFound()); + } + next(); + }); + } + next(); // Required, so error later +} + +var Note = new restful.Model({ + title: "note", + methods: ['get', 'delete', { type: 'post', before: validateUser }, { type: 'put', before: validateUser }], + schema: mongoose.Schema({ + title: { type: 'string', required: true}, + body: { type: 'string', required: true}, + creator: { type: 'ObjectId', ref: 'user', require: true}, + }), +}); + +exports = module.exports = Note; diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/node-restful/examples/notes/models/user.js b/common/src/main/webapp/usageguide/appserver/node_modules/node-restful/examples/notes/models/user.js new file mode 100644 index 0000000..384e318 --- /dev/null +++ b/common/src/main/webapp/usageguide/appserver/node_modules/node-restful/examples/notes/models/user.js @@ -0,0 +1,13 @@ +var restful = require('../../..'), + mongoose = require('mongoose'); + +var User = new restful.Model({ + title: 'user', + methods: ['get', 'post', 'put', 'delete'], + schema: mongoose.Schema({ + username: 'string', + password: 'string', + }), +}); + +exports = module.exports = User; |