From 2a897e0befd3f8d3cba54fd70554d1c064c36f02 Mon Sep 17 00:00:00 2001 From: jkaplon Date: Wed, 5 Aug 2015 14:46:33 -0400 Subject: [PATCH] Add local time/date and devcie name conversions to alert email. --- alertmonUtils.js | 12 ++++++++++++ server.js | 8 ++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/alertmonUtils.js b/alertmonUtils.js index 99aa6e5..0230820 100644 --- a/alertmonUtils.js +++ b/alertmonUtils.js @@ -11,3 +11,15 @@ exports.getLocDateFromUTC = function(utcDtTm) { localDt = moment(localDt).tz('America/New_York').format('MM-DD-YYYY'); return localDt; }; + +exports.getCoreNameFromCoreId = function(db, coreId) { + db.all('SELECT coreName FROM Cores WHERE coreId = ? LIMIT 1;', coreId, function(err, rows){ + if (err !== null) { + console.log(err); + } else { + return rows.coreName; + } + } + ); + +}; diff --git a/server.js b/server.js index 57dfb66..cc8f300 100644 --- a/server.js +++ b/server.js @@ -176,9 +176,6 @@ app.get('/core/:id', function(req, res){ // Loop over elements in rows array, convert ugly UTC times to pretty local times. rows.forEach(function(row){ - //var localDtTm = moment.utc(new Date(row.published_at)); - //localDtTm = moment(localDtTm).tz('America/New_York').format('MM-DD-YYYY HH:mm:ss'); - //row.published_at = localDtTm; row.pubDate = alertmonUtils.getLocDateFromUTC(row.published_at); row.pubTime = alertmonUtils.getLocTimeFromUTC(row.published_at); }); @@ -188,7 +185,6 @@ app.get('/core/:id', function(req, res){ }); } }); - //res.send; }); app.post('/', function(req, res){ @@ -213,8 +209,8 @@ app.post('/', function(req, res){ if(status.toLowerCase().indexOf('alert') > -1){ 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'; + mailOptions.text = mailOptions.text + 'Published at, ' + alertmonUtils.getLocDateFromUTC(pubAt) + ' ' + alertmonUtils.getLocTimeFromUTC(pubAt) + '\n'; + mailOptions.text = mailOptions.text + 'From device, ' + alertmonUtils.getCoreNameFromCoreId(coreid) + '\n'; transporter.sendMail(mailOptions, function(error, info){ if(error){