add route to list changes

This commit is contained in:
Trowbridge 2019-03-22 14:02:03 -04:00
parent d968237ea7
commit 429baa0c04
2 changed files with 52 additions and 0 deletions

View File

@ -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) { server.post('/addmonth_v', bodyParser.json(), function (req, res) {
var sql = ""; var sql = "";

View File

@ -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