add undo route, and include comments

This commit is contained in:
Trowbridge 2020-02-14 14:41:29 -05:00
parent b881fae5b4
commit 6485613ab7
3 changed files with 45 additions and 2 deletions

View File

@ -80,6 +80,7 @@ server.get('/get_pool', bodyParser.json(), function(req, res) {
console.log(new Date().toISOString() + "-------------------------get pool:----------------------------"); console.log(new Date().toISOString() + "-------------------------get pool:----------------------------");
console.log(req.body.quota_rep); console.log(req.body.quota_rep);
sql = sql.replace("rep_replace", req.body.quota_rep); sql = sql.replace("rep_replace", req.body.quota_rep);
console.log(sql);
Postgres.FirstRow(sql, [], res) Postgres.FirstRow(sql, [], res)
}; };
@ -164,6 +165,37 @@ server.get('/list_changes', bodyParser.json(), function(req, res) {
}; };
}) })
server.get('/undo_change', bodyParser.json(), function(req, res) {
var sql = "";
var w = "";
var c = 1;
var d = 1;
var args = [];
var path = './route_sql/undo.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(new Date().toISOString() + "-------------------------undo change:------------------------------")
console.log(req.body);
//parse the where clause into the main sql statement
sql = sql.replace(new RegExp("replace_id", 'g'), JSON.stringify(req.body.logid))
//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

@ -29,14 +29,17 @@ SELECT
,request_season ,request_season
,request_month ,request_month
,promo ,promo
,version
,iter
--------values------------------------- --------values-------------------------
,sum(value_loc) value_loc ,sum(value_loc) value_loc
,sum(value_usd) value_usd ,sum(value_usd) value_usd
,sum(cost_loc) cost_loc ,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd ,sum(cost_usd) cost_usd
,sum(units) units ,sum(units) units
,version
,iter
,logid
,comment
,module
FROM FROM
rlarp.osm_pool rlarp.osm_pool
WHERE WHERE
@ -73,6 +76,9 @@ GROUP BY
,promo ,promo
,version ,version
,iter ,iter
,logid
,comment
,module
) )
SELECT SELECT
json_agg(row_to_json(rows)) x json_agg(row_to_json(rows)) x

5
route_sql/undo.sql Normal file
View File

@ -0,0 +1,5 @@
WITH
d AS (
DELETE FROM rlarp.osm_log WHERE id = replace_id RETURNING id
)
SELECT json_agg(row_to_json(d)) x from d