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