From aa67562d5b9d6171161c922f7c1d99e3f52f2c36 Mon Sep 17 00:00:00 2001 From: Trowbridge Date: Fri, 1 Mar 2019 15:37:00 -0500 Subject: [PATCH] add new package route --- index.js | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/index.js b/index.js index 46cd573..e11e7ed 100644 --- a/index.js +++ b/index.js @@ -83,6 +83,104 @@ server.get('/scenario_totals', bodyParser.json(), function (req, res) { //res.json("hi") }) +server.get('/scenario_package', bodyParser.json(), function (req, res) { + + var w = ""; + var c = 1; + var args = []; + + for (var i in req.body) { + //console.log(i); + ///console.log(req.body[i]); + if (c > 1) { + w = w + + ` + AND ` + } + w = w + i + " = '" + req.body[i] + "'"; + args.push(req.body[i]); + c = c + 1; + }; + if (c == 1) { + res.send("no body was sent"); + return; + } + //console.log(w); + //console.log(args); + w = + ` + WITH base AS ( + SELECT + order_season + ,order_month + ,version + ,iter + ,part_descr + ,bill_cust_descr + ,ship_cust_descr + ,SUM(units) units + ,SUM(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + `+ w + + `GROUP BY + order_season + ,order_month + ,version + ,iter + ,part_descr + ,bill_cust_descr + ,ship_cust_descr + ) + ,months AS ( + SELECT + order_season + ,version + ,iter + ,order_month + ,sum(units) units + ,sum(value_usd) value_usd + FROM + base + GROUP BY + order_season + ,version + ,iter + ,order_month + ) + ,totals AS ( + SELECT + order_season + ,version + ,iter + ,sum(units) units + ,sum(value_usd) value_usd + FROM + months + GROUP BY + order_season + ,version + ,iter + ) + SELECT + jsonb_build_object( + 'months' + ,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months) + ) + ,jsonb_build_object( + 'base' + ,(SELECT jsonb_agg(row_to_json(base)::jsonb) FROM base) + ) + ,jsonb_build_object( + 'totals' + ,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals) + )` + console.log(w); + Postgres.FirstRow(w, [], res) + //res.json("hi") +}) + server.get('/get_pool', bodyParser.json(), function (req, res) { var args = [req.body.quota_rep];