Fix field names on index.hbs; removed rows w/NULL published_at values from DB (showed year=1969 on home page); update email code to be postgres-compliant.
This commit is contained in:
parent
11b4c05830
commit
92adabcd47
54
server.js
54
server.js
@ -57,7 +57,7 @@ app.get('/', function(req, res){
|
|||||||
}
|
}
|
||||||
var devIndexQry =
|
var devIndexQry =
|
||||||
"select status, published_at " +
|
"select status, published_at " +
|
||||||
"from Alerts " +
|
"from alerts " +
|
||||||
"where status in ('Open', 'Closed') " +
|
"where status in ('Open', 'Closed') " +
|
||||||
"order by published_at desc " +
|
"order by published_at desc " +
|
||||||
"limit 2"
|
"limit 2"
|
||||||
@ -69,11 +69,12 @@ app.get('/', function(req, res){
|
|||||||
}
|
}
|
||||||
// Loop over elements in rows array, convert ugly UTC times to pretty local times.
|
// Loop over elements in rows array, convert ugly UTC times to pretty local times.
|
||||||
result.rows.forEach(function(row){
|
result.rows.forEach(function(row){
|
||||||
row.pubDate = courtsopenUtils.getLocDateFromUTC(row.published_at);
|
winston.info(row.published_at);
|
||||||
row.pubTime = courtsopenUtils.getLocTimeFromUTC(row.published_at);
|
row.pubdate = courtsopenUtils.getLocDateFromUTC(row.published_at);
|
||||||
|
row.pubtime = courtsopenUtils.getLocTimeFromUTC(row.published_at);
|
||||||
if(row.status.toLowerCase().indexOf('closed') > -1){
|
if(row.status.toLowerCase().indexOf('closed') > -1){
|
||||||
row.statusClass = 'closed';
|
row.statusclass = 'closed';
|
||||||
} else { row.statusClass = 'open'; }
|
} else { row.statusclass = 'open'; }
|
||||||
});
|
});
|
||||||
|
|
||||||
res.render('index', {values: result.rows}, function(err, html) {
|
res.render('index', {values: result.rows}, function(err, html) {
|
||||||
@ -120,7 +121,7 @@ app.post('/', function(req, res){
|
|||||||
};
|
};
|
||||||
var received_at = new Date(Date.now());
|
var received_at = new Date(Date.now());
|
||||||
received_at = received_at.toISOString();
|
received_at = received_at.toISOString();
|
||||||
console.log(statusFromCode + ' ' + received_at);
|
winston.info(statusFromCode + ' ' + received_at);
|
||||||
pg.connect(conString, function(err, client, done) {
|
pg.connect(conString, function(err, client, done) {
|
||||||
if(err) { return console.error('error fetching client from pool', err); }
|
if(err) { return console.error('error fetching client from pool', err); }
|
||||||
client.query(
|
client.query(
|
||||||
@ -128,30 +129,37 @@ app.post('/', function(req, res){
|
|||||||
[JSON.stringify(req.body, null, 4), deviceid, received_at, statusFromCode]
|
[JSON.stringify(req.body, null, 4), deviceid, received_at, statusFromCode]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
res.status(204).send('POST received');
|
res.status(204).send('POST received');
|
||||||
});
|
});
|
||||||
|
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
// Check every hour to see if GoodMorning or GoodEvening has gone missing.
|
// Check every hour to see if GoodMorning or GoodEvening has gone missing.
|
||||||
var deadManQry = "select published_at from Alerts where datetime(published_at) > datetime('now', '-14.5 hours') order by datetime(published_at) limit 1";
|
pg.connect(conString, function(err, client, done) {
|
||||||
db.get(deadManQry, function(err, row){
|
if(err) {
|
||||||
if (err !== null) { winston.error(err); }
|
return winston.error('error fetching client from pool', err);
|
||||||
else if (typeof row == "undefined") {
|
|
||||||
mailOptions.text = "It's been too long since the last data transmission from device. \n\n";
|
|
||||||
winston.info(mailOptions.text);
|
|
||||||
// Don't include any other details for now, will need to change DB query to get details on last message received.
|
|
||||||
//mailOptions.text = mailOptions.text + 'Status message, ' + status + '\n';
|
|
||||||
//mailOptions.text = mailOptions.text + 'Published at, ' + courtsopenUtils.getLocDateFromUTC(pubAt) + ' ' + courtsopenUtils.getLocTimeFromUTC(pubAt) + '\n';
|
|
||||||
transporter.sendMail(mailOptions, function(error, info){
|
|
||||||
if(error){
|
|
||||||
winston.info(error);
|
|
||||||
}else{
|
|
||||||
winston.info('Message sent: ' + info.response);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
var deadManQry = "select published_at from alerts where to_timestamp(published_at, 'YYYY-MM-DD HH24:MI:SS') > (now() - interval '14.5 hours') limit 1";
|
||||||
|
client.query(deadManQry, function(err, result) {
|
||||||
|
//call `done()` to release the client back to the pool
|
||||||
|
done();
|
||||||
|
if(err) {
|
||||||
|
return winston.error('error running query', err);
|
||||||
|
} else if (typeof result == "undefined") {
|
||||||
|
mailOptions.text = "It's been too long since the last data transmission from device. \n\n";
|
||||||
|
winston.info(mailOptions.text);
|
||||||
|
// Don't include any other details for now, will need to change DB query to get details on last message received.
|
||||||
|
//mailOptions.text = mailOptions.text + 'Status message, ' + status + '\n';
|
||||||
|
//mailOptions.text = mailOptions.text + 'Published at, ' + courtsopenUtils.getLocDateFromUTC(pubAt) + ' ' + courtsopenUtils.getLocTimeFromUTC(pubAt) + '\n';
|
||||||
|
transporter.sendMail(mailOptions, function(error, info){
|
||||||
|
if(error){
|
||||||
|
winston.info(error);
|
||||||
|
}else{
|
||||||
|
winston.info('Message sent: ' + info.response);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}, 60 * 60 * 1000);
|
}, 60 * 60 * 1000);
|
||||||
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
{{!< default}}
|
{{!< default}}
|
||||||
|
|
||||||
{{! Index-0 is the most recent message. }}
|
{{! Index-0 is the most recent message. }}
|
||||||
<div class="jumbotron {{values.0.statusClass}}">
|
<div class="jumbotron {{values.0.statusclass}}">
|
||||||
<h1 class="text-center"><b>{{values.0.status}}</b></h1>
|
<h1 class="text-center"><b>{{values.0.status}}</b></h1>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h3 class="text-center">Update received: {{values.0.pubDate}}, {{values.0.pubTime}}</h3>
|
<h3 class="text-center">Update received: {{values.0.pubdate}}, {{values.0.pubtime}}</h3>
|
||||||
</div>
|
</div>
|
||||||
<hr></hr>
|
<hr></hr>
|
||||||
<div>
|
<div>
|
||||||
<h4 class="text-center">Prior update was: {{values.1.status}} at {{values.1.pubDate}}, {{values.1.pubTime}}</h4>
|
<h4 class="text-center">Prior update was: {{values.1.status}} at {{values.1.pubdate}}, {{values.1.pubtime}}</h4>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr></hr>
|
<hr></hr>
|
||||||
|
Loading…
Reference in New Issue
Block a user