add new package route
This commit is contained in:
parent
0520775a00
commit
aa67562d5b
98
index.js
98
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];
|
||||
|
Loading…
Reference in New Issue
Block a user