From db3b267657495e79a05de5bd4cc3b042ae239ce0 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 12 May 2022 00:27:31 -0400 Subject: [PATCH] create local variables in build where and return as newly named --- index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index bda0b2e..527d7c6 100644 --- a/index.js +++ b/index.js @@ -40,10 +40,13 @@ const SQLTemplate = (inSql, inJSON) => { } return inSql; }; -const build_where = (req, c, w, d, args) => { +const build_where = (req, c, w) => { //loop through each top level item expected to be a simple key/value list reflecting the column and the target value // "part":"XFRM500", "customer":"Sanford and Son" --> SQL --> part = 'XFRM500' // AND customer = 'Sanford and Son' + var d = 1; + var args = []; + for (var i in req.body.app_scenario) { //console.log(i); ///console.log(req.body[i]); @@ -71,7 +74,7 @@ const build_where = (req, c, w, d, args) => { args.push(req.body.app_scenario[i]); c = c + 1; }; - return { c, w, d }; + return { c, w }; } //------------route to test if the process is running------------------------------- @@ -110,11 +113,9 @@ server.get('/baseline', bodyParser.json(), function(req, res) { server.get('/scale', bodyParser.json(), function(req, res) { var sql = ""; - var w = ""; //holds the where - var c = 1; //flag if body is empty - var d = 1; + var where = ""; //holds the where + var check = 1; //flag if body is empty var path = './routes/scale/scale.sql'; - var args = []; fs.readFile(path, 'utf8', function(err, data) { @@ -124,7 +125,7 @@ server.get('/scale', bodyParser.json(), function(req, res) { return } - let { check, where } = build_where(req, c, w, d, args); + ({ c: check, w: where } = build_where(req, check, where)); //if there was no body sent, return with nothing //if (c == 1) { // res.send("no body was sent");