-
-
Save robzolkos/91eda1bb6f67ae513204 to your computer and use it in GitHub Desktop.
SO Question re callbacks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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