Skip to content

Instantly share code, notes, and snippets.

@robzolkos
Created April 30, 2013 11:08
Show Gist options
  • Save robzolkos/91eda1bb6f67ae513204 to your computer and use it in GitHub Desktop.
Save robzolkos/91eda1bb6f67ae513204 to your computer and use it in GitHub Desktop.
SO Question re callbacks
var models = require("../models");
exports.events = function(req, res) {
var Edm = models.Edm;
if (req.query.event) {
if (req.query.campaignguid) {
var list_id;
Edm.find({where: {campaignguid: req.query.campaignguid}}).success(function(edm) {
list_id = edm.id;
switch (req.query.event) {
case 'processed':
increment_counter(req.query.event, list_id, function(err, retval) {
console.log("return value is " + retval);
res.writeHead(200);
res.end();
})
break;
}
});
} else {
if (req.query.userguid) {
console.log("userguid is present");
}
}
}
}
function increment_counter(field, id, callback) {
var Edm = models.Edm;
Edm.find(id).success(function(edm) {
edm.increment(field, 1).success(function(e) {
console.log("incremented the field!");
return callback(null, e.processed);
});
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment