Skip to content

Instantly share code, notes, and snippets.

@dperussina
Last active August 20, 2019 17:15
Show Gist options
  • Save dperussina/027800b8791b4645e63a85795a2295e5 to your computer and use it in GitHub Desktop.
Save dperussina/027800b8791b4645e63a85795a2295e5 to your computer and use it in GitHub Desktop.
module.exports.MyRoute= function(req, res){
var request = req.query;
var response = {
error: false,
errorText: '',
data: []
};
function ValidateRequest(next){
// Do what you need to do, then call next
next(false); // If error to break series, pass true
}
function Query1(next){
// Do what you need to do, then call next
var sproc = "exec some_proc @Variable = '"+request.SomeVariable+"'";
SQL(sproc, function(err, reply){
if(err){
// handle
}
// success
reply.data = reply;
next(false); // If error to break series, pass true
});
}
function Query2(next){
// Do what you need to do, then call next
var sproc = "exec some_proc2 @Variable = '"+request.SomeOtherVariable+"'";
SQL(sproc, function(err, reply){
if(err){
// handle
}
// success
reply.second_data = reply; // Name is more relative to data returned
next(false); // If error to break series, pass true
});
}
function Query3(next){
// Do what you need to do, then call next
var sproc = "exec last_proc @Variable = '"+request.LastVariable+"'";
SQL(sproc, function(err, reply){
if(err){
// handle
}
// success
reply.last_data = reply; // Name is more relative to data returned
next(false); // If error to break series, pass true
});
}
function FinalizeAndReply(err, reply){
if (err) {
response.error= true;
response.errorText = reply.toString();
}
var json = JSON.stringify(response);
res.send(json);
}
async.series([ValidateRequest, Query1, Query2, Query3], FinalizeAndReply);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment