diff --git a/README.md b/README.md index 0d4ecb7..8195473 100644 --- a/README.md +++ b/README.md @@ -43,27 +43,27 @@ var PizzaSchema = new Schema({ // You can optionally add a method to schema.methods that is executed based // on the type of HTTP request with the names "query", "get", "put", "post", and "delete" // The callback receives the affected entities as it's parameter. -PizzaSchema.methods.query = function(entities) { +PizzaSchema.methods.query = function(entities, request) { console.log("Queried:"); console.log(entities); }; -PizzaSchema.methods.get = function(entity) { +PizzaSchema.methods.get = function(entity, request) { console.log("Got:") console.log(entity); }; -PizzaSchema.methods.put = function(entity) { +PizzaSchema.methods.put = function(entity, request) { console.log("Put:") console.log(entity); }; -PizzaSchema.methods.post = function(entity) { +PizzaSchema.methods.post = function(entity, request) { console.log("Posted:") console.log(entity); }; -PizzaSchema.methods.delete = function(entity) { +PizzaSchema.methods.delete = function(entity, request) { console.log("Deleted:") console.log(entity); }; diff --git a/lib/index.js b/lib/index.js index bc65a5a..ed92977 100644 --- a/lib/index.js +++ b/lib/index.js @@ -106,8 +106,10 @@ AngularBridge.prototype.collectionGet = function() { if (err) { return self.renderError(err, null, req, res, next); } else { - if(req.resource.model.schema.methods.query) req.resource.model.schema.methods.query(docs); - res.send(docs); + if(req.resource.model.schema.methods.query){ + req.resource.model.schema.methods.query(docs, req); + } + res.send(docs); } return false; }); @@ -129,10 +131,9 @@ AngularBridge.prototype.collectionPost = function() { self.renderError(err, null, req, res, next); return; } - - if (doc.schema.methods.post) - doc.schema.methods.post(doc); - + if(doc.schema.methods.post){ + doc.schema.methods.post(doc, req); + } res.send(doc); }); }, this); @@ -224,7 +225,9 @@ AngularBridge.prototype.entityGet = function() { if (!req.resource) { return next(); } - if(req.doc.schema.methods.get) req.doc.schema.methods.get(req.doc); + if(req.doc.schema.methods.get){ + req.doc.schema.methods.get(req.doc, req); + } return res.send(req.doc); }, this); }; @@ -246,7 +249,9 @@ AngularBridge.prototype.entityPut = function() { if (err) { return res.send({success:false}); } - if (req.doc.schema.methods.put) req.doc.schema.methods.put(req.doc); + if(req.doc.schema.methods.put){ + req.doc.schema.methods.put(req.doc, req); + } return res.send(req.doc); }); }, this); @@ -260,7 +265,9 @@ AngularBridge.prototype.entityDelete = function() { if (err) { return res.send({success : false}); } - if (req.doc.schema.methods.delete) req.doc.schema.methods.delete(req.doc); + if(req.doc.schema.methods.delete){ + req.doc.schema.methods.delete(req.doc, req); + } return res.send({success : true}); }); }, this);