Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
25 changes: 16 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand All @@ -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);
Expand Down Expand Up @@ -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);
};
Expand All @@ -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);
Expand All @@ -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);
Expand Down