add route to list changes
This commit is contained in:
parent
d968237ea7
commit
429baa0c04
31
index.js
31
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 = "";
|
||||
|
21
route_sql/list_changes.sql
Normal file
21
route_sql/list_changes.sql
Normal 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
|
Loading…
Reference in New Issue
Block a user