port building of where clause to global in all routes

This commit is contained in:
Paul Trowbridge 2019-03-13 13:28:40 -04:00
parent c1ee6134d8
commit b65b52d25b

View File

@ -167,24 +167,15 @@ server.post('/addmonth_vp', bodyParser.json(), function (req, res) {
var sql = ""; var sql = "";
var w = ""; var w = "";
var c = 1; var c = 1;
var d = 1;
var args = []; var args = [];
var path = './route_sql/addmonth_vupd.sql'; var path = './route_sql/addmonth_vupd.sql';
var callback = function(arg){ var callback = function(arg){
sql = arg sql = arg
for (var i in req.body.scenario) { ({ c, w, d } = build_where(req, c, w, d, args));
//console.log(i);
///console.log(req.body[i]);
if (c > 1) {
w = w +
`
AND `
}
w = w + i + " = '" + req.body.scenario[i] + "'";
args.push(req.body.scenario[i]);
c = c + 1;
};
if (c == 1) { if (c == 1) {
res.send("no body was sent"); res.send("no body was sent");
return; return;
@ -215,24 +206,15 @@ server.post('/scale_v', bodyParser.json(), function (req, res) {
var sql = ""; var sql = "";
var w = ""; var w = "";
var c = 1; var c = 1;
var d = 1;
var args = []; var args = [];
var path = './route_sql/scale_vd.sql'; var path = './route_sql/scale_vd.sql';
var callback = function(arg){ var callback = function(arg){
sql = arg sql = arg
for (var i in req.body.scenario) { ({ c, w, d } = build_where(req, c, w, d, args));
//console.log(i);
///console.log(req.body[i]);
if (c > 1) {
w = w +
`
AND `
}
w = w + i + " = '" + req.body.scenario[i] + "'";
args.push(req.body.scenario[i]);
c = c + 1;
};
if (c == 1) { if (c == 1) {
res.send("no body was sent"); res.send("no body was sent");
return; return;
@ -261,24 +243,15 @@ server.post('/scale_p', bodyParser.json(), function (req, res) {
var sql = ""; var sql = "";
var w = ""; var w = "";
var c = 1; var c = 1;
var d = 1;
var args = []; var args = [];
var path = './route_sql/scale_pd.sql'; var path = './route_sql/scale_pd.sql';
var callback = function(arg){ var callback = function(arg){
sql = arg sql = arg
for (var i in req.body.scenario) { ({ c, w, d } = build_where(req, c, w, d, args));
//console.log(i);
///console.log(req.body[i]);
if (c > 1) {
w = w +
`
AND `
}
w = w + i + " = '" + req.body.scenario[i] + "'";
args.push(req.body.scenario[i]);
c = c + 1;
};
if (c == 1) { if (c == 1) {
res.send("no body was sent"); res.send("no body was sent");
return; return;
@ -307,24 +280,15 @@ server.post('/scale_vp', bodyParser.json(), function (req, res) {
var sql = ""; var sql = "";
var w = ""; var w = "";
var c = 1; var c = 1;
var d = 1;
var args = []; var args = [];
var path = './route_sql/scale_vupd.sql'; var path = './route_sql/scale_vupd.sql';
var callback = function(arg){ var callback = function(arg){
sql = arg sql = arg
for (var i in req.body.scenario) { ({ c, w, d } = build_where(req, c, w, d, args));
//console.log(i);
///console.log(req.body[i]);
if (c > 1) {
w = w +
`
AND `
}
w = w + i + " = '" + req.body.scenario[i] + "'";
args.push(req.body.scenario[i]);
c = c + 1;
};
if (c == 1) { if (c == 1) {
res.send("no body was sent"); res.send("no body was sent");
return; return;