Merge branch 'undo' of hc-companies/forecast_api into dev
This commit is contained in:
commit
7d50a37e29
34
index.js
34
index.js
@ -80,6 +80,7 @@ server.get('/get_pool', bodyParser.json(), function(req, res) {
|
||||
console.log(new Date().toISOString() + "-------------------------get pool:----------------------------");
|
||||
console.log(req.body.quota_rep);
|
||||
sql = sql.replace("rep_replace", req.body.quota_rep);
|
||||
console.log(sql);
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
};
|
||||
|
||||
@ -128,7 +129,7 @@ server.get('/scenario_package', bodyParser.json(), function(req, res) {
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w)
|
||||
//execute the sql and send the result
|
||||
//console.log(sql);
|
||||
console.log(sql);
|
||||
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) {
|
||||
|
||||
var sql = "";
|
||||
|
@ -101,8 +101,8 @@ SELECT
|
||||
,version
|
||||
,iter
|
||||
,null::int logid
|
||||
,null::text "comment"
|
||||
,null::text module
|
||||
,''::text "comment"
|
||||
,''::text module
|
||||
FROM
|
||||
rlarp.osmf_dev o
|
||||
LEFT OUTER JOIN lgdat.cust bc ON
|
||||
|
@ -29,14 +29,17 @@ SELECT
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,comment
|
||||
,module
|
||||
FROM
|
||||
rlarp.osm_pool
|
||||
WHERE
|
||||
@ -73,6 +76,9 @@ GROUP BY
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,comment
|
||||
,module
|
||||
)
|
||||
SELECT
|
||||
json_agg(row_to_json(rows)) x
|
||||
|
@ -332,7 +332,7 @@ SELECT
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' volume' iter
|
||||
,log.id
|
||||
,log.doc->>'comment' "comment"
|
||||
,COALESCE(log.doc->>'message','') "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
basemix b
|
||||
@ -452,6 +452,9 @@ FROM
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,comment
|
||||
,module
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
@ -492,5 +495,8 @@ FROM
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,comment
|
||||
,module
|
||||
)
|
||||
SELECT json_agg(row_to_json(insagg)) x from insagg
|
@ -167,7 +167,7 @@ target AS (select target_increment incr)
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' price' iter
|
||||
,log.id
|
||||
,log.doc->>'comment' "comment"
|
||||
,COALESCE(log.doc->>'message','') "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
basemix b
|
||||
@ -213,6 +213,9 @@ target AS (select target_increment incr)
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,comment
|
||||
,module
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
@ -253,5 +256,8 @@ target AS (select target_increment incr)
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,comment
|
||||
,module
|
||||
)
|
||||
SELECT json_agg(row_to_json(insagg)) x from insagg
|
||||
|
@ -196,7 +196,7 @@ target AS (select incr_qty qincr)
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' volume' iter
|
||||
,log.id
|
||||
,log.doc->>'comment' "comment"
|
||||
,COALESCE(log.doc->>'message','') "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
basemix b
|
||||
@ -240,6 +240,9 @@ FROM
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,comment
|
||||
,module
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
@ -280,5 +283,8 @@ FROM
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,comment
|
||||
,module
|
||||
)
|
||||
SELECT json_agg(row_to_json(insagg)) x from insagg
|
@ -195,7 +195,7 @@ target AS (select target_vol vincr, target_prc pincr)
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' volume' iter
|
||||
,log.id
|
||||
,log.doc->>'comment' "comment"
|
||||
,COALESCE(log.doc->>'message','') "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
basemix b
|
||||
@ -274,7 +274,7 @@ FROM
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' price' iter
|
||||
,log.id
|
||||
,log.doc->>'comment' "comment"
|
||||
,COALESCE(log.doc->>'message','') "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
volume b
|
||||
@ -320,6 +320,9 @@ FROM
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,comment
|
||||
,module
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
@ -360,5 +363,8 @@ FROM
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,comment
|
||||
,module
|
||||
)
|
||||
SELECT json_agg(row_to_json(insagg)) x from insagg
|
||||
|
8
route_sql/undo.sql
Normal file
8
route_sql/undo.sql
Normal file
@ -0,0 +1,8 @@
|
||||
WITH
|
||||
d AS (
|
||||
DELETE FROM rlarp.osm_log WHERE id = replace_id RETURNING id
|
||||
)
|
||||
,d_osm AS (
|
||||
DELETE FROM rlarp.osm_pool WHERE logid IN (select id from d)
|
||||
)
|
||||
SELECT json_agg(row_to_json(d)) x from d
|
Loading…
Reference in New Issue
Block a user