Parse status message out of inner JSON and include value in DB insert; show alert status in email

This commit is contained in:
jkaplon 2015-07-14 17:40:23 -04:00
parent 058152aca4
commit e1652a8d90

View File

@ -106,19 +106,22 @@ app.get('/core/:id', function(req, res){
app.post('/', function(req, res){ app.post('/', function(req, res){
var postEvent = req.body.postEvent; var postEvent = req.body.postEvent;
var source = req.body.source; var source = req.body.source;
//console.log("Post event = "+postEvent+", source is "+source);
console.log(req.body); console.log(req.body);
var stmt = db.prepare("INSERT INTO Alerts (OrigJSON, coreid, published_at) VALUES (?, ?, ?)"); var innerDataJSON = JSON.parse(req.body.data);
var status = JSON.stringify(innerDataJSON.status, null, 4);
var stmt = db.prepare("INSERT INTO Alerts (OrigJSON, coreid, published_at, status) VALUES (?, ?, ?, ?)");
stmt.run( stmt.run(
JSON.stringify(req.body, null, 4), JSON.stringify(req.body, null, 4),
JSON.stringify(req.body.coreid, null, 4), JSON.stringify(req.body.coreid, null, 4),
JSON.stringify(req.body.published_at, null, 4) JSON.stringify(req.body.published_at, null, 4),
status
); );
stmt.finalize(); stmt.finalize();
// Send emails on alerts only // Send emails on alerts only
if(JSON.stringify(req.body, null, 4).indexOf('alert') > -1){ if(JSON.stringify(req.body, null, 4).indexOf('alert') > -1){
mailOptions.text = status;
transporter.sendMail(mailOptions, function(error, info){ transporter.sendMail(mailOptions, function(error, info){
if(error){ if(error){
console.log(error); console.log(error);