From 31da09399d963d766bd299fac1212a48b20f1b4b Mon Sep 17 00:00:00 2001 From: jkaplon Date: Thu, 30 Jul 2015 10:08:09 -0400 Subject: [PATCH] Basic fix for issue #26, still need to test new device. --- server.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server.js b/server.js index 15f4982..3930e71 100644 --- a/server.js +++ b/server.js @@ -63,10 +63,10 @@ app.get('/', function(req, res){ var d = new Date(); console.log("GET /, " + JSON.stringify(d, 4)); var devIndexQry = - "select coreId, coreName, locationDesc, max(published_at) as MaxPub, max(status) as MaxStatus " + - "from Alerts otbl " + - "where coreName = (select max(coreName) from Alerts where coreId = otbl.coreId) " + - "group by coreId, coreName, locationDesc;"; + "select al.coreId, max(co.coreName) as coreName, max(co.locationDesc) as locationDesc, max(published_at) as MaxPub, max(status) as MaxStatus " + + "from Alerts al " + + "left join Cores co on al.coreId = co.coreId " + + "group by al.coreId;"; db.all(devIndexQry, function(err, rows){ if(err !== null) { console.log(err); @@ -122,8 +122,10 @@ app.post('/core/edit/:id', function(req, res){ } else { // check existence of row in Cores table, if there update, otherwise insert. var existQry = "SELECT coreId FROM Cores WHERE coreId = ?;" - db.get(existQry, function(err, row){ + db.get(existQry, coreId, function(err, row){ if(err) throw err; + console.log(typeof row); + console.log(row); if(typeof row == "undefined") { var insStmt = db.prepare("INSERT INTO Cores (coreId, coreName, locationDesc) VALUES (?, ?, ?);"); insStmt.run( @@ -141,7 +143,6 @@ app.post('/core/edit/:id', function(req, res){ ); stmt.finalize(); } - } if (req.body.locationDesc !== "") { var stmt = db.prepare("UPDATE Cores SET locationDesc = ? WHERE coreId = ?"); @@ -164,7 +165,10 @@ app.get('/core/:id', function(req, res){ var d = new Date(); var coreId = req.params.id; console.log("GET /core/" + coreId + ", " + JSON.stringify(d, 4)); - db.all("SELECT coreId, published_at, status, coreName FROM Alerts WHERE coreId = ? ORDER BY published_at DESC LIMIT 30;", coreId, function(err, rows){ + var coreMsgQry = "SELECT al.coreId, al.published_at, al.status, co.coreName " + + "FROM Alerts al left join Cores co on al.coreId = co.coreId " + + "WHERE al.coreId = ? ORDER BY al.published_at DESC LIMIT 30;" + db.all(coreMsgQry, coreId, function(err, rows){ if(err !== null) { console.log(err); } else {