Parse status message out of inner JSON and include value in DB insert; show alert status in email
This commit is contained in:
parent
058152aca4
commit
e1652a8d90
@ -106,19 +106,22 @@ app.get('/core/:id', function(req, res){
|
||||
app.post('/', function(req, res){
|
||||
var postEvent = req.body.postEvent;
|
||||
var source = req.body.source;
|
||||
//console.log("Post event = "+postEvent+", source is "+source);
|
||||
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(
|
||||
JSON.stringify(req.body, 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();
|
||||
|
||||
// Send emails on alerts only
|
||||
if(JSON.stringify(req.body, null, 4).indexOf('alert') > -1){
|
||||
mailOptions.text = status;
|
||||
transporter.sendMail(mailOptions, function(error, info){
|
||||
if(error){
|
||||
console.log(error);
|
||||
|
Loading…
Reference in New Issue
Block a user