Added more detail to alert email, but still needs work, relates to issue #14.

This commit is contained in:
jkaplon 2015-08-04 19:44:06 -04:00
parent 8155a05d7c
commit 1590fb9f17

View File

@ -200,19 +200,25 @@ app.post('/', function(req, res){
console.log(req.body);
var innerDataJSON = JSON.parse(req.body.data);
var status = JSON.stringify(innerDataJSON.status, null, 4);
var status = JSON.stringify(innerDataJSON.status, null, 4).slice(1,-1);
var coreid = JSON.stringify(req.body.coreid, null, 4).slice(1,-1);
var pubAt = JSON.stringify(req.body.published_at, null, 4).slice(1,-1);
var stmt = db.prepare("INSERT INTO Alerts (OrigJSON, coreid, published_at, status) VALUES (?, ?, ?, ?)");
stmt.run( // Use .slice to get rid of leading and trailing double quotes.
JSON.stringify(req.body, null, 4),
JSON.stringify(req.body.coreid, null, 4).slice(1,-1),
JSON.stringify(req.body.published_at, null, 4).slice(1,-1),
status.slice(1,-1)
coreid,
pubAt,
status
);
stmt.finalize();
// Send emails on alerts only
if(status.toLowerCase().indexOf('alert') > -1){
mailOptions.text = status;
mailOptions.text = 'An alert message was received: \n\n';
mailOptions.text = mailOptions.text + 'Status message, ' + status + '\n';
mailOptions.text = mailOptions.text + 'Published at, ' + pubAt + '\n';
mailOptions.text = mailOptions.text + 'From device, ' + coreid + '\n';
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log(error);