Basic fix for issue #26, still need to test new device.
This commit is contained in:
parent
788c446916
commit
31da09399d
18
server.js
18
server.js
@ -63,10 +63,10 @@ app.get('/', function(req, res){
|
|||||||
var d = new Date();
|
var d = new Date();
|
||||||
console.log("GET /, " + JSON.stringify(d, 4));
|
console.log("GET /, " + JSON.stringify(d, 4));
|
||||||
var devIndexQry =
|
var devIndexQry =
|
||||||
"select coreId, coreName, locationDesc, max(published_at) as MaxPub, max(status) as MaxStatus " +
|
"select al.coreId, max(co.coreName) as coreName, max(co.locationDesc) as locationDesc, max(published_at) as MaxPub, max(status) as MaxStatus " +
|
||||||
"from Alerts otbl " +
|
"from Alerts al " +
|
||||||
"where coreName = (select max(coreName) from Alerts where coreId = otbl.coreId) " +
|
"left join Cores co on al.coreId = co.coreId " +
|
||||||
"group by coreId, coreName, locationDesc;";
|
"group by al.coreId;";
|
||||||
db.all(devIndexQry, function(err, rows){
|
db.all(devIndexQry, function(err, rows){
|
||||||
if(err !== null) {
|
if(err !== null) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@ -122,8 +122,10 @@ app.post('/core/edit/:id', function(req, res){
|
|||||||
} else {
|
} else {
|
||||||
// check existence of row in Cores table, if there update, otherwise insert.
|
// check existence of row in Cores table, if there update, otherwise insert.
|
||||||
var existQry = "SELECT coreId FROM Cores WHERE coreId = ?;"
|
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;
|
if(err) throw err;
|
||||||
|
console.log(typeof row);
|
||||||
|
console.log(row);
|
||||||
if(typeof row == "undefined") {
|
if(typeof row == "undefined") {
|
||||||
var insStmt = db.prepare("INSERT INTO Cores (coreId, coreName, locationDesc) VALUES (?, ?, ?);");
|
var insStmt = db.prepare("INSERT INTO Cores (coreId, coreName, locationDesc) VALUES (?, ?, ?);");
|
||||||
insStmt.run(
|
insStmt.run(
|
||||||
@ -141,7 +143,6 @@ app.post('/core/edit/:id', function(req, res){
|
|||||||
);
|
);
|
||||||
stmt.finalize();
|
stmt.finalize();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (req.body.locationDesc !== "") {
|
if (req.body.locationDesc !== "") {
|
||||||
var stmt = db.prepare("UPDATE Cores SET locationDesc = ? WHERE coreId = ?");
|
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 d = new Date();
|
||||||
var coreId = req.params.id;
|
var coreId = req.params.id;
|
||||||
console.log("GET /core/" + coreId + ", " + JSON.stringify(d, 4));
|
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) {
|
if(err !== null) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user