From 429baa0c0433b517c0d1795a9854cc541029f8d9 Mon Sep 17 00:00:00 2001 From: Trowbridge Date: Fri, 22 Mar 2019 14:02:03 -0400 Subject: [PATCH] add route to list changes --- index.js | 31 +++++++++++++++++++++++++++++++ route_sql/list_changes.sql | 21 +++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 route_sql/list_changes.sql diff --git a/index.js b/index.js index 1e8799a..3e71223 100644 --- a/index.js +++ b/index.js @@ -126,6 +126,37 @@ server.get('/scenario_package', bodyParser.json(), function (req, res) { }; }) +server.get('/list_changes', bodyParser.json(), function (req, res) { + + var sql = ""; + var w = ""; + var c = 1; + var d = 1; + var args = []; + var path = './route_sql/list_changes.sql'; + + fs.readFile(path, 'utf8', function(err, data){ + if (!err){ + callback(data); + } else { + console.log("fatal error pulling sql file") + callback(err); + } + }); + + var callback = function(arg){ + sql = arg; + + console.log("-------------------------get scenario:------------------------------") + console.log(req.body); + //parse the where clause into the main sql statement + sql = sql.replace(new RegExp("replace_user",'g'),JSON.stringify(req.body)) + //execute the sql and send the result + //console.log(sql); + Postgres.FirstRow(sql,[],res) + }; +}) + server.post('/addmonth_v', bodyParser.json(), function (req, res) { var sql = ""; diff --git a/route_sql/list_changes.sql b/route_sql/list_changes.sql new file mode 100644 index 0000000..34f04a4 --- /dev/null +++ b/route_sql/list_changes.sql @@ -0,0 +1,21 @@ +WITH +list AS ( +SELECT + iterdef->>'user' "user", + iterdef->>'stamp' "stamp", + iterdef->>'mesasage' "comment", + round(SUM(fb_val_loc * r_rate)::numeric,2) sales, + jsonb_pretty(iterdef) def +FROM + rlarp.osm_fcpool +WHERE + iterdef IS NOT NULL + AND iterdef @> $$replace_user$$::jsonb +GROUP BY + iterdef->>'user', + iterdef->>'stamp', + iterdef->>'message', + iterdef +) +SELECT + jsonb_agg(row_to_json(list)::jsonb) x from list \ No newline at end of file