Compare commits
2 Commits
8aeecc845b
...
1b8c101429
Author | SHA1 | Date | |
---|---|---|---|
|
1b8c101429 | ||
|
6e8f026770 |
258
index.js
258
index.js
@ -18,8 +18,8 @@ var options = {
|
|||||||
passprase: []
|
passprase: []
|
||||||
};
|
};
|
||||||
|
|
||||||
https.createServer(options,server).listen(process.env.nodeport, () => {
|
https.createServer(options, server).listen(process.env.nodeport, () => {
|
||||||
console.log('started on '+ process.env.nodeport)
|
console.log('started on ' + process.env.nodeport)
|
||||||
});
|
});
|
||||||
//server.listen(3000, () => console.log('started'))
|
//server.listen(3000, () => console.log('started'))
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ var Postgres = new pg.Client({
|
|||||||
});
|
});
|
||||||
Postgres.connect();
|
Postgres.connect();
|
||||||
|
|
||||||
Postgres.FirstRow = function (inSQL, args, inResponse) {
|
Postgres.FirstRow = function(inSQL, args, inResponse) {
|
||||||
Postgres.query(inSQL, args, (err, res) => {
|
Postgres.query(inSQL, args, (err, res) => {
|
||||||
if (err === null) {
|
if (err === null) {
|
||||||
inResponse.json(res.rows[0]);
|
inResponse.json(res.rows[0]);
|
||||||
@ -42,7 +42,7 @@ Postgres.FirstRow = function (inSQL, args, inResponse) {
|
|||||||
}
|
}
|
||||||
console.log(err.stack);
|
console.log(err.stack);
|
||||||
inResponse.json(err.stack);
|
inResponse.json(err.stack);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
server.get('/', (req, res) => res.send('node.js express is up and running'))
|
server.get('/', (req, res) => res.send('node.js express is up and running'))
|
||||||
@ -55,14 +55,14 @@ server.get('/pgbadger', (req, res) => res.sendFile(process.env.wd + 'logs.html')
|
|||||||
|
|
||||||
server.get('/totals', (req, res) => res.sendFile(process.env.wd + 'totals.log'))
|
server.get('/totals', (req, res) => res.sendFile(process.env.wd + 'totals.log'))
|
||||||
|
|
||||||
server.get('/test_sql', function(req, res){
|
server.get('/test_sql', function(req, res) {
|
||||||
var path = './route_meta/scenario_package.sql'
|
var path = './route_meta/scenario_package.sql'
|
||||||
var callback = function(arg){
|
var callback = function(arg) {
|
||||||
res.send(arg)
|
res.send(arg)
|
||||||
};
|
};
|
||||||
|
|
||||||
fs.readFile(path, 'utf8', function(err, data){
|
fs.readFile(path, 'utf8', function(err, data) {
|
||||||
if (!err){
|
if (!err) {
|
||||||
callback(data);
|
callback(data);
|
||||||
} else {
|
} else {
|
||||||
callback(err);
|
callback(err);
|
||||||
@ -70,21 +70,21 @@ server.get('/test_sql', function(req, res){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
server.get('/get_pool', bodyParser.json(), function (req, res) {
|
server.get('/get_pool', bodyParser.json(), function(req, res) {
|
||||||
|
|
||||||
var sql = "";
|
var sql = "";
|
||||||
var args = [req.body.quota_rep];
|
var args = [req.body.quota_rep];
|
||||||
var path = './route_sql/get_pool.sql';
|
var path = './route_sql/get_pool.sql';
|
||||||
var callback = function(arg){
|
var callback = function(arg) {
|
||||||
sql = arg;
|
sql = arg;
|
||||||
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);
|
||||||
Postgres.FirstRow(sql,[],res)
|
Postgres.FirstRow(sql, [], res)
|
||||||
};
|
};
|
||||||
|
|
||||||
fs.readFile(path, 'utf8', function(err, data){
|
fs.readFile(path, 'utf8', function(err, data) {
|
||||||
if (!err){
|
if (!err) {
|
||||||
callback(data);
|
callback(data);
|
||||||
} else {
|
} else {
|
||||||
console.log("fatal error pulling sql file")
|
console.log("fatal error pulling sql file")
|
||||||
@ -94,7 +94,7 @@ server.get('/get_pool', bodyParser.json(), function (req, res) {
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
server.get('/scenario_package', bodyParser.json(), function (req, res) {
|
server.get('/scenario_package', bodyParser.json(), function(req, res) {
|
||||||
|
|
||||||
var sql = "";
|
var sql = "";
|
||||||
var w = "";
|
var w = "";
|
||||||
@ -103,8 +103,8 @@ server.get('/scenario_package', bodyParser.json(), function (req, res) {
|
|||||||
var args = [];
|
var args = [];
|
||||||
var path = './route_sql/scenario_package.sql';
|
var path = './route_sql/scenario_package.sql';
|
||||||
|
|
||||||
fs.readFile(path, 'utf8', function(err, data){
|
fs.readFile(path, 'utf8', function(err, data) {
|
||||||
if (!err){
|
if (!err) {
|
||||||
callback(data);
|
callback(data);
|
||||||
} else {
|
} else {
|
||||||
console.log("fatal error pulling sql file")
|
console.log("fatal error pulling sql file")
|
||||||
@ -112,9 +112,9 @@ server.get('/scenario_package', bodyParser.json(), function (req, res) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var callback = function(arg){
|
var callback = function(arg) {
|
||||||
sql = arg;
|
sql = arg;
|
||||||
|
|
||||||
//parse request body into a where clause
|
//parse request body into a where clause
|
||||||
({ c, w, d } = build_where(req, c, w, d, args));
|
({ c, w, d } = build_where(req, c, w, d, args));
|
||||||
|
|
||||||
@ -126,14 +126,14 @@ server.get('/scenario_package', bodyParser.json(), function (req, res) {
|
|||||||
console.log(new Date().toISOString() + "-------------------------get scenario:------------------------------")
|
console.log(new Date().toISOString() + "-------------------------get scenario:------------------------------")
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
//parse the where clause into the main sql statement
|
//parse the where clause into the main sql statement
|
||||||
sql = sql.replace(new RegExp("where_clause",'g'),w)
|
sql = sql.replace(new RegExp("where_clause", 'g'), w)
|
||||||
//execute the sql and send the result
|
//execute the sql and send the result
|
||||||
//console.log(sql);
|
//console.log(sql);
|
||||||
Postgres.FirstRow(sql,[],res)
|
Postgres.FirstRow(sql, [], res)
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
server.get('/list_changes', bodyParser.json(), function (req, res) {
|
server.get('/list_changes', bodyParser.json(), function(req, res) {
|
||||||
|
|
||||||
var sql = "";
|
var sql = "";
|
||||||
var w = "";
|
var w = "";
|
||||||
@ -142,8 +142,8 @@ server.get('/list_changes', bodyParser.json(), function (req, res) {
|
|||||||
var args = [];
|
var args = [];
|
||||||
var path = './route_sql/list_changes.sql';
|
var path = './route_sql/list_changes.sql';
|
||||||
|
|
||||||
fs.readFile(path, 'utf8', function(err, data){
|
fs.readFile(path, 'utf8', function(err, data) {
|
||||||
if (!err){
|
if (!err) {
|
||||||
callback(data);
|
callback(data);
|
||||||
} else {
|
} else {
|
||||||
console.log("fatal error pulling sql file")
|
console.log("fatal error pulling sql file")
|
||||||
@ -151,20 +151,20 @@ server.get('/list_changes', bodyParser.json(), function (req, res) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var callback = function(arg){
|
var callback = function(arg) {
|
||||||
sql = arg;
|
sql = arg;
|
||||||
|
|
||||||
console.log(new Date().toISOString() +"-------------------------list changes:------------------------------")
|
console.log(new Date().toISOString() + "-------------------------list changes:------------------------------")
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
//parse the where clause into the main sql statement
|
//parse the where clause into the main sql statement
|
||||||
sql = sql.replace(new RegExp("replace_user",'g'),JSON.stringify(req.body))
|
sql = sql.replace(new RegExp("replace_user", 'g'), JSON.stringify(req.body.quota_rep_descr))
|
||||||
//execute the sql and send the result
|
//execute the sql and send the result
|
||||||
//console.log(sql);
|
console.log(sql);
|
||||||
Postgres.FirstRow(sql,[],res)
|
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 = "";
|
||||||
var w = "";
|
var w = "";
|
||||||
@ -173,16 +173,16 @@ server.post('/addmonth_v', bodyParser.json(), function (req, res) {
|
|||||||
var args = [];
|
var args = [];
|
||||||
var path = './route_sql/addmonth_vd.sql';
|
var path = './route_sql/addmonth_vd.sql';
|
||||||
|
|
||||||
fs.readFile(path, 'utf8', function(err, data){
|
fs.readFile(path, 'utf8', function(err, data) {
|
||||||
if (!err){
|
if (!err) {
|
||||||
callback(data);
|
callback(data);
|
||||||
} else {
|
} else {
|
||||||
console.log("fatal error pulling sql file")
|
console.log("fatal error pulling sql file")
|
||||||
callback(err);
|
callback(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var callback = function(arg){
|
var callback = function(arg) {
|
||||||
sql = arg;
|
sql = arg;
|
||||||
//buile where clause expression
|
//buile where clause expression
|
||||||
({ c, w, d } = build_where(req, c, w, d, args));
|
({ c, w, d } = build_where(req, c, w, d, args));
|
||||||
@ -191,22 +191,22 @@ server.post('/addmonth_v', bodyParser.json(), function (req, res) {
|
|||||||
res.send("no body was sent");
|
res.send("no body was sent");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(new Date().toISOString() +"-----------------------------add month volume:---------------------------------");
|
console.log(new Date().toISOString() + "-----------------------------add month volume:---------------------------------");
|
||||||
req.body.stamp = new Date().toISOString()
|
req.body.stamp = new Date().toISOString()
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
//console.log(args);
|
//console.log(args);
|
||||||
sql = sql.replace(new RegExp("scenario = target_scenario",'g'),w);
|
sql = sql.replace(new RegExp("scenario = target_scenario", 'g'), w);
|
||||||
sql = sql.replace(new RegExp("target_increment",'g'),req.body.qty);
|
sql = sql.replace(new RegExp("target_increment", 'g'), req.body.qty);
|
||||||
sql = sql.replace(new RegExp("target_month",'g'),req.body.month);
|
sql = sql.replace(new RegExp("target_month", 'g'), req.body.month);
|
||||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||||
sql = sql.replace(new RegExp("replace_source",'g'),req.body.source);
|
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||||
sql = sql.replace(new RegExp("replace_iterdef",'g'),JSON.stringify(req.body));
|
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||||
console.log(sql)
|
console.log(sql)
|
||||||
Postgres.FirstRow(sql,[],res)
|
Postgres.FirstRow(sql, [], res)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
server.post('/addmonth_vp', bodyParser.json(), function (req, res) {
|
server.post('/addmonth_vp', bodyParser.json(), function(req, res) {
|
||||||
|
|
||||||
var sql = "";
|
var sql = "";
|
||||||
var w = "";
|
var w = "";
|
||||||
@ -214,8 +214,8 @@ server.post('/addmonth_vp', bodyParser.json(), function (req, res) {
|
|||||||
var d = 1;
|
var d = 1;
|
||||||
var args = [];
|
var args = [];
|
||||||
var path = './route_sql/addmonth_vupd.sql';
|
var path = './route_sql/addmonth_vupd.sql';
|
||||||
|
|
||||||
var callback = function(arg){
|
var callback = function(arg) {
|
||||||
sql = arg;
|
sql = arg;
|
||||||
|
|
||||||
({ c, w, d } = build_where(req, c, w, d, args));
|
({ c, w, d } = build_where(req, c, w, d, args));
|
||||||
@ -224,23 +224,23 @@ server.post('/addmonth_vp', bodyParser.json(), function (req, res) {
|
|||||||
res.send("no body was sent");
|
res.send("no body was sent");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(new Date().toISOString() +"------------------add month volume and price:-------------------");
|
console.log(new Date().toISOString() + "------------------add month volume and price:-------------------");
|
||||||
req.body.stamp = new Date().toISOString()
|
req.body.stamp = new Date().toISOString()
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
//console.log(args);
|
//console.log(args);
|
||||||
sql = sql.replace(new RegExp("where_clause",'g'),w);
|
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||||
sql = sql.replace(new RegExp("target_volume",'g'),req.body.qty);
|
sql = sql.replace(new RegExp("target_volume", 'g'), req.body.qty);
|
||||||
sql = sql.replace(new RegExp("target_price",'g'),req.body.amount);
|
sql = sql.replace(new RegExp("target_price", 'g'), req.body.amount);
|
||||||
sql = sql.replace(new RegExp("target_month",'g'),req.body.month);
|
sql = sql.replace(new RegExp("target_month", 'g'), req.body.month);
|
||||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||||
sql = sql.replace(new RegExp("replace_source",'g'),req.body.source);
|
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||||
sql = sql.replace(new RegExp("replace_iterdef",'g'),JSON.stringify(req.body));
|
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||||
console.log(sql);
|
console.log(sql);
|
||||||
Postgres.FirstRow(sql,[],res)
|
Postgres.FirstRow(sql, [], res)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.readFile(path, 'utf8', function(err, data){
|
fs.readFile(path, 'utf8', function(err, data) {
|
||||||
if (!err){
|
if (!err) {
|
||||||
callback(data);
|
callback(data);
|
||||||
} else {
|
} else {
|
||||||
console.log("fatal error pulling sql file")
|
console.log("fatal error pulling sql file")
|
||||||
@ -249,7 +249,7 @@ server.post('/addmonth_vp', bodyParser.json(), function (req, res) {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
server.post('/scale_v', bodyParser.json(), function (req, res) {
|
server.post('/scale_v', bodyParser.json(), function(req, res) {
|
||||||
|
|
||||||
var sql = "";
|
var sql = "";
|
||||||
var w = "";
|
var w = "";
|
||||||
@ -257,8 +257,8 @@ server.post('/scale_v', bodyParser.json(), function (req, res) {
|
|||||||
var d = 1;
|
var d = 1;
|
||||||
var args = [];
|
var args = [];
|
||||||
var path = './route_sql/scale_vd.sql';
|
var path = './route_sql/scale_vd.sql';
|
||||||
|
|
||||||
var callback = function(arg){
|
var callback = function(arg) {
|
||||||
sql = arg;
|
sql = arg;
|
||||||
|
|
||||||
({ c, w, d } = build_where(req, c, w, d, args));
|
({ c, w, d } = build_where(req, c, w, d, args));
|
||||||
@ -267,21 +267,21 @@ server.post('/scale_v', bodyParser.json(), function (req, res) {
|
|||||||
res.send("no body was sent");
|
res.send("no body was sent");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(new Date().toISOString() +"-----------------------scale volume:------------------------------");
|
console.log(new Date().toISOString() + "-----------------------scale volume:------------------------------");
|
||||||
req.body.stamp = new Date().toISOString()
|
req.body.stamp = new Date().toISOString()
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
//console.log(args);
|
//console.log(args);
|
||||||
sql = sql.replace(new RegExp("where_clause",'g'),w);
|
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||||
sql = sql.replace(new RegExp("incr_qty",'g'),req.body.qty);
|
sql = sql.replace(new RegExp("incr_qty", 'g'), req.body.qty);
|
||||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||||
sql = sql.replace(new RegExp("replace_source",'g'),req.body.source);
|
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||||
sql = sql.replace(new RegExp("replace_iterdef",'g'),JSON.stringify(req.body));
|
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||||
console.log(sql);
|
console.log(sql);
|
||||||
Postgres.FirstRow(sql,[],res)
|
Postgres.FirstRow(sql, [], res)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.readFile(path, 'utf8', function(err, data){
|
fs.readFile(path, 'utf8', function(err, data) {
|
||||||
if (!err){
|
if (!err) {
|
||||||
callback(data);
|
callback(data);
|
||||||
} else {
|
} else {
|
||||||
console.log("fatal error pulling sql file")
|
console.log("fatal error pulling sql file")
|
||||||
@ -290,7 +290,7 @@ server.post('/scale_v', bodyParser.json(), function (req, res) {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
server.post('/scale_p', bodyParser.json(), function (req, res) {
|
server.post('/scale_p', bodyParser.json(), function(req, res) {
|
||||||
|
|
||||||
var sql = "";
|
var sql = "";
|
||||||
var w = "";
|
var w = "";
|
||||||
@ -298,8 +298,8 @@ server.post('/scale_p', bodyParser.json(), function (req, res) {
|
|||||||
var d = 1;
|
var d = 1;
|
||||||
var args = [];
|
var args = [];
|
||||||
var path = './route_sql/scale_pd.sql';
|
var path = './route_sql/scale_pd.sql';
|
||||||
|
|
||||||
var callback = function(arg){
|
var callback = function(arg) {
|
||||||
sql = arg;
|
sql = arg;
|
||||||
|
|
||||||
({ c, w, d } = build_where(req, c, w, d, args));
|
({ c, w, d } = build_where(req, c, w, d, args));
|
||||||
@ -308,21 +308,21 @@ server.post('/scale_p', bodyParser.json(), function (req, res) {
|
|||||||
res.send("no body was sent");
|
res.send("no body was sent");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(new Date().toISOString() +"--------------------scale price:-------------------");
|
console.log(new Date().toISOString() + "--------------------scale price:-------------------");
|
||||||
req.body.stamp = new Date().toISOString()
|
req.body.stamp = new Date().toISOString()
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
//console.log(args);
|
//console.log(args);
|
||||||
sql = sql.replace(new RegExp("where_clause",'g'),w);
|
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||||
sql = sql.replace(new RegExp("target_increment",'g'),req.body.amount);
|
sql = sql.replace(new RegExp("target_increment", 'g'), req.body.amount);
|
||||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||||
sql = sql.replace(new RegExp("replace_source",'g'),req.body.source);
|
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||||
sql = sql.replace(new RegExp("replace_iterdef",'g'),JSON.stringify(req.body));
|
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||||
console.log(sql);
|
console.log(sql);
|
||||||
Postgres.FirstRow(sql,[],res)
|
Postgres.FirstRow(sql, [], res)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.readFile(path, 'utf8', function(err, data){
|
fs.readFile(path, 'utf8', function(err, data) {
|
||||||
if (!err){
|
if (!err) {
|
||||||
callback(data);
|
callback(data);
|
||||||
} else {
|
} else {
|
||||||
console.log("fatal error pulling sql file")
|
console.log("fatal error pulling sql file")
|
||||||
@ -331,7 +331,7 @@ server.post('/scale_p', bodyParser.json(), function (req, res) {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
server.post('/scale_vp', bodyParser.json(), function (req, res) {
|
server.post('/scale_vp', bodyParser.json(), function(req, res) {
|
||||||
|
|
||||||
var sql = "";
|
var sql = "";
|
||||||
var w = "";
|
var w = "";
|
||||||
@ -339,8 +339,8 @@ server.post('/scale_vp', bodyParser.json(), function (req, res) {
|
|||||||
var d = 1;
|
var d = 1;
|
||||||
var args = [];
|
var args = [];
|
||||||
var path = './route_sql/scale_vupd.sql';
|
var path = './route_sql/scale_vupd.sql';
|
||||||
|
|
||||||
var callback = function(arg){
|
var callback = function(arg) {
|
||||||
sql = arg;
|
sql = arg;
|
||||||
|
|
||||||
({ c, w, d } = build_where(req, c, w, d, args));
|
({ c, w, d } = build_where(req, c, w, d, args));
|
||||||
@ -349,22 +349,22 @@ server.post('/scale_vp', bodyParser.json(), function (req, res) {
|
|||||||
res.send("no body was sent");
|
res.send("no body was sent");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(new Date().toISOString() +"--------------------scale volume & price:-------------------");
|
console.log(new Date().toISOString() + "--------------------scale volume & price:-------------------");
|
||||||
req.body.stamp = new Date().toISOString()
|
req.body.stamp = new Date().toISOString()
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
//console.log(args);
|
//console.log(args);
|
||||||
sql = sql.replace(new RegExp("where_clause",'g'),w);
|
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||||
sql = sql.replace(new RegExp("target_vol",'g'),req.body.qty);
|
sql = sql.replace(new RegExp("target_vol", 'g'), req.body.qty);
|
||||||
sql = sql.replace(new RegExp("target_prc",'g'),req.body.amount);
|
sql = sql.replace(new RegExp("target_prc", 'g'), req.body.amount);
|
||||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||||
sql = sql.replace(new RegExp("replace_source",'g'),req.body.source);
|
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||||
sql = sql.replace(new RegExp("replace_iterdef",'g'),JSON.stringify(req.body));
|
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||||
console.log(sql);
|
console.log(sql);
|
||||||
Postgres.FirstRow(sql,[],res)
|
Postgres.FirstRow(sql, [], res)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.readFile(path, 'utf8', function(err, data){
|
fs.readFile(path, 'utf8', function(err, data) {
|
||||||
if (!err){
|
if (!err) {
|
||||||
callback(data);
|
callback(data);
|
||||||
} else {
|
} else {
|
||||||
console.log("fatal error pulling sql file")
|
console.log("fatal error pulling sql file")
|
||||||
@ -373,7 +373,7 @@ server.post('/scale_vp', bodyParser.json(), function (req, res) {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
server.post('/new_part', bodyParser.json(), function (req, res) {
|
server.post('/new_part', bodyParser.json(), function(req, res) {
|
||||||
|
|
||||||
var sql = "";
|
var sql = "";
|
||||||
var w = "";
|
var w = "";
|
||||||
@ -381,8 +381,8 @@ server.post('/new_part', bodyParser.json(), function (req, res) {
|
|||||||
var d = 1;
|
var d = 1;
|
||||||
var args = [];
|
var args = [];
|
||||||
var path = './route_sql/new_part.sql';
|
var path = './route_sql/new_part.sql';
|
||||||
|
|
||||||
var callback = function(arg){
|
var callback = function(arg) {
|
||||||
sql = arg;
|
sql = arg;
|
||||||
|
|
||||||
({ c, w, d } = build_where(req, c, w, d, args));
|
({ c, w, d } = build_where(req, c, w, d, args));
|
||||||
@ -391,23 +391,23 @@ server.post('/new_part', bodyParser.json(), function (req, res) {
|
|||||||
res.send("no body was sent");
|
res.send("no body was sent");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(new Date().toISOString() +"--------------------new part:-------------------");
|
console.log(new Date().toISOString() + "--------------------new part:-------------------");
|
||||||
req.body.stamp = new Date().toISOString()
|
req.body.stamp = new Date().toISOString()
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
//console.log(args);
|
//console.log(args);
|
||||||
sql = sql.replace(new RegExp("where_clause",'g'),w);
|
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||||
sql = sql.replace(new RegExp("target_vol",'g'),req.body.qty);
|
sql = sql.replace(new RegExp("target_vol", 'g'), req.body.qty);
|
||||||
sql = sql.replace(new RegExp("target_prc",'g'),req.body.amount);
|
sql = sql.replace(new RegExp("target_prc", 'g'), req.body.amount);
|
||||||
sql = sql.replace(new RegExp("replace_request",'g'),JSON.stringify(req.body));
|
sql = sql.replace(new RegExp("replace_request", 'g'), JSON.stringify(req.body));
|
||||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||||
sql = sql.replace(new RegExp("replace_source",'g'),req.body.source);
|
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||||
sql = sql.replace(new RegExp("replace_iterdef",'g'),JSON.stringify(req.body));
|
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||||
console.log(sql);
|
console.log(sql);
|
||||||
Postgres.FirstRow(sql,[],res)
|
Postgres.FirstRow(sql, [], res)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.readFile(path, 'utf8', function(err, data){
|
fs.readFile(path, 'utf8', function(err, data) {
|
||||||
if (!err){
|
if (!err) {
|
||||||
callback(data);
|
callback(data);
|
||||||
} else {
|
} else {
|
||||||
console.log("fatal error pulling sql file")
|
console.log("fatal error pulling sql file")
|
||||||
@ -416,7 +416,7 @@ server.post('/new_part', bodyParser.json(), function (req, res) {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
server.post('/new_basket', bodyParser.json(), function (req, res) {
|
server.post('/new_basket', bodyParser.json(), function(req, res) {
|
||||||
|
|
||||||
var sql = "";
|
var sql = "";
|
||||||
var w = "";
|
var w = "";
|
||||||
@ -424,8 +424,8 @@ server.post('/new_basket', bodyParser.json(), function (req, res) {
|
|||||||
var d = 1;
|
var d = 1;
|
||||||
var args = [];
|
var args = [];
|
||||||
var path = './route_sql/new_basket.sql';
|
var path = './route_sql/new_basket.sql';
|
||||||
|
|
||||||
var callback = function(arg){
|
var callback = function(arg) {
|
||||||
sql = arg;
|
sql = arg;
|
||||||
|
|
||||||
({ c, w, d } = build_where(req, c, w, d, args));
|
({ c, w, d } = build_where(req, c, w, d, args));
|
||||||
@ -434,23 +434,23 @@ server.post('/new_basket', bodyParser.json(), function (req, res) {
|
|||||||
res.send("no body was sent");
|
res.send("no body was sent");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(new Date().toISOString() +"--------------------new basket:-------------------");
|
console.log(new Date().toISOString() + "--------------------new basket:-------------------");
|
||||||
req.body.stamp = new Date().toISOString()
|
req.body.stamp = new Date().toISOString()
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
//console.log(args);
|
//console.log(args);
|
||||||
sql = sql.replace(new RegExp("where_clause",'g'),w);
|
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||||
sql = sql.replace(new RegExp("target_vol",'g'),req.body.qty);
|
sql = sql.replace(new RegExp("target_vol", 'g'), req.body.qty);
|
||||||
sql = sql.replace(new RegExp("target_prc",'g'),req.body.amount);
|
sql = sql.replace(new RegExp("target_prc", 'g'), req.body.amount);
|
||||||
sql = sql.replace(new RegExp("replace_request",'g'),JSON.stringify(req.body));
|
sql = sql.replace(new RegExp("replace_request", 'g'), JSON.stringify(req.body));
|
||||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
|
||||||
sql = sql.replace(new RegExp("replace_source",'g'),req.body.source);
|
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
|
||||||
sql = sql.replace(new RegExp("replace_iterdef",'g'),JSON.stringify(req.body));
|
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
|
||||||
console.log(sql);
|
console.log(sql);
|
||||||
Postgres.FirstRow(sql,[],res)
|
Postgres.FirstRow(sql, [], res)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.readFile(path, 'utf8', function(err, data){
|
fs.readFile(path, 'utf8', function(err, data) {
|
||||||
if (!err){
|
if (!err) {
|
||||||
callback(data);
|
callback(data);
|
||||||
} else {
|
} else {
|
||||||
console.log("fatal error pulling sql file")
|
console.log("fatal error pulling sql file")
|
||||||
@ -480,13 +480,11 @@ function build_where(req, c, w, d, args) {
|
|||||||
d = d + 1;
|
d = d + 1;
|
||||||
}
|
}
|
||||||
w = w + ")";
|
w = w + ")";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
w = w + i + " = '" + req.body.scenario[i] + "'";
|
w = w + i + " = '" + req.body.scenario[i] + "'";
|
||||||
}
|
}
|
||||||
args.push(req.body.scenario[i]);
|
args.push(req.body.scenario[i]);
|
||||||
c = c + 1;
|
c = c + 1;
|
||||||
}
|
};
|
||||||
;
|
|
||||||
return { c, w, d };
|
return { c, w, d };
|
||||||
}
|
}
|
@ -1,21 +1,37 @@
|
|||||||
WITH
|
WITH
|
||||||
list AS (
|
list AS materialized (
|
||||||
SELECT
|
SELECT
|
||||||
iterdef->>'user' "user",
|
l.doc->>'user' "user",
|
||||||
iterdef->>'stamp' "stamp",
|
jsonb_path_query_first(l.doc,'$.scenario.quota_rep_descr')->>0 quota_rep_descr,
|
||||||
iterdef->>'mesasage' "comment",
|
to_char((l.doc->>'stamp')::timestamptz,'YYYY-MM-DD HH:MI:SS') "stamp",
|
||||||
round(SUM(fb_val_loc * r_rate)::numeric,2) sales,
|
l.doc->>'message' "comment",
|
||||||
jsonb_pretty(iterdef) def
|
jsonb_pretty(l.doc) def,
|
||||||
|
l.id
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm_fcpool
|
rlarp.osm_log l
|
||||||
WHERE
|
WHERE
|
||||||
iterdef IS NOT NULL
|
l.doc @? '$.scenario.quota_rep_descr ? (@ == replace_user)'
|
||||||
AND iterdef @> $$replace_user$$::jsonb
|
)
|
||||||
GROUP BY
|
,agg as (
|
||||||
iterdef->>'user',
|
SELECT
|
||||||
iterdef->>'stamp',
|
list.user
|
||||||
iterdef->>'message',
|
,list.quota_rep_descr
|
||||||
iterdef
|
,list.stamp
|
||||||
|
,list.comment
|
||||||
|
,list.def
|
||||||
|
,list.id
|
||||||
|
,to_char(round(sum(value_usd),2),'$999,999,999D00') sales
|
||||||
|
from
|
||||||
|
LIST
|
||||||
|
inner join rlarp.osm_pool on
|
||||||
|
id = logid
|
||||||
|
group BY
|
||||||
|
list.user
|
||||||
|
,list.quota_rep_descr
|
||||||
|
,list.stamp
|
||||||
|
,list.comment
|
||||||
|
,list.def
|
||||||
|
,list.id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
jsonb_agg(row_to_json(list)::jsonb) x from list
|
jsonb_agg(row_to_json(agg)::jsonb ORDER BY agg.stamp desc) x from agg
|
@ -254,9 +254,9 @@ SELECT
|
|||||||
LEFT OUTER JOIN gld od ON
|
LEFT OUTER JOIN gld od ON
|
||||||
od.drange @> make_date(mxm.yr + 2021,mxm.cal,mxm.odom)
|
od.drange @> make_date(mxm.yr + 2021,mxm.cal,mxm.odom)
|
||||||
LEFT OUTER JOIN gld rd ON
|
LEFT OUTER JOIN gld rd ON
|
||||||
od.drange @> (make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag)
|
rd.drange @> (make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag)
|
||||||
LEFT OUTER JOIN gld sd ON
|
LEFT OUTER JOIN gld sd ON
|
||||||
od.drange @> (make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag + slag)
|
sd.drange @> (make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag + slag)
|
||||||
)
|
)
|
||||||
--SELECT * FROM basemix
|
--SELECT * FROM basemix
|
||||||
,log AS (
|
,log AS (
|
||||||
|
Loading…
Reference in New Issue
Block a user