Last active
August 20, 2019 17:15
-
-
Save dperussina/027800b8791b4645e63a85795a2295e5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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