add route to pull monthly totals for scenario
This commit is contained in:
parent
6ba6b3691a
commit
d4a954750a
50
index.js
50
index.js
@ -1,5 +1,6 @@
|
|||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
|
var bodyParser = require('body-parser');
|
||||||
const server = express();
|
const server = express();
|
||||||
const pg = require('pg');
|
const pg = require('pg');
|
||||||
|
|
||||||
@ -32,9 +33,52 @@ server.get('/list_sources', function (req,res) {
|
|||||||
Postgres.FirstRow(sql,[],res);
|
Postgres.FirstRow(sql,[],res);
|
||||||
})
|
})
|
||||||
|
|
||||||
server.get('/rep_list', function (req,res) {
|
server.get('/rep_list', bodyParser.json(), function (req,res) {
|
||||||
var sql = "select jsonb_agg(quota_rep) from (select distinct quota_rep from rlarp.osm) x";
|
|
||||||
Postgres.FirstRow(sql,[],res);
|
//console.log(JSON.stringify(req.body));
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
//console.log(w);
|
||||||
|
//console.log(args);
|
||||||
|
w =
|
||||||
|
`
|
||||||
|
WITH
|
||||||
|
ini AS (
|
||||||
|
SELECT
|
||||||
|
oseas
|
||||||
|
,extract('month' from odate) monthn
|
||||||
|
,sum(qty) qty
|
||||||
|
,sum(sales) sales
|
||||||
|
,sum(stdcost) stdcost
|
||||||
|
FROM
|
||||||
|
rlarp.osm_ppfa_varto_mv
|
||||||
|
WHERE
|
||||||
|
` + w +
|
||||||
|
`
|
||||||
|
GROUP BY
|
||||||
|
oseas
|
||||||
|
,extract('month' from odate)
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
jsonb_agg(row_to_json(ini)::jsonb)
|
||||||
|
FROM
|
||||||
|
ini`
|
||||||
|
console.log(w);
|
||||||
|
Postgres.FirstRow(w,[],res)
|
||||||
|
//res.json("hi")
|
||||||
})
|
})
|
||||||
|
|
||||||
server.get('/', (req,res) => res.send('its running yay 🎡'))
|
server.get('/', (req,res) => res.send('its running yay 🎡'))
|
||||||
|
Loading…
Reference in New Issue
Block a user