diff --git a/index.js b/index.js index 05477ad..e2e4cf5 100644 --- a/index.js +++ b/index.js @@ -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;