Remove extra server endpoints, closes #13.
This commit is contained in:
parent
81ed5d154f
commit
7c8c3c0189
98
server.js
98
server.js
@ -98,104 +98,6 @@ app.get('/', function(req, res){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/core/edit/:id', function(req, res){
|
|
||||||
var d = new Date();
|
|
||||||
var coreId = req.params.id;
|
|
||||||
console.log("GET /core/edit/" + coreId + ", " + JSON.stringify(d, 4));
|
|
||||||
|
|
||||||
db.all("select coreName, locationDesc from Cores where coreId = ?;", coreId, function(err, rows){
|
|
||||||
if(err !== null) {
|
|
||||||
console.log(err);
|
|
||||||
} else {
|
|
||||||
res.render('core-edit', {values: rows}, function(err, html) {
|
|
||||||
if(err !== null) {
|
|
||||||
console.log(err);
|
|
||||||
} else {
|
|
||||||
res.send(html);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.post('/core/edit/:id', function(req, res){
|
|
||||||
var d = new Date();
|
|
||||||
var coreId = req.params.id;
|
|
||||||
console.log("POST /core/edit/" + coreId + "body: " + JSON.stringify(req.body) + ", " + JSON.stringify(d, 4));
|
|
||||||
if (!req.body) {
|
|
||||||
return res.sendStatus(400);
|
|
||||||
} else {
|
|
||||||
// check existence of row in Cores table, if there update, otherwise insert.
|
|
||||||
var existQry = "SELECT coreId FROM Cores WHERE coreId = ?;"
|
|
||||||
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(
|
|
||||||
coreId,
|
|
||||||
req.body.deviceName,
|
|
||||||
req.body.locationDesc
|
|
||||||
);
|
|
||||||
insStmt.finalize();
|
|
||||||
} else {
|
|
||||||
if (req.body.deviceName !== "") {
|
|
||||||
var stmt = db.prepare("UPDATE Cores SET coreName = ? WHERE coreId = ?");
|
|
||||||
stmt.run(
|
|
||||||
req.body.deviceName,
|
|
||||||
coreId
|
|
||||||
);
|
|
||||||
stmt.finalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.body.locationDesc !== "") {
|
|
||||||
var stmt = db.prepare("UPDATE Cores SET locationDesc = ? WHERE coreId = ?");
|
|
||||||
stmt.run(
|
|
||||||
req.body.locationDesc,
|
|
||||||
coreId
|
|
||||||
);
|
|
||||||
stmt.finalize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
res.redirect('https://tenniscourtsopen.com/');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/core/:id', function(req, res){
|
|
||||||
//res.sendFile("/usr/src/app/index.html");
|
|
||||||
//fs.createReadStream('./log.log').pipe(res);
|
|
||||||
var d = new Date();
|
|
||||||
var coreId = req.params.id;
|
|
||||||
console.log("GET /core/" + coreId + ", " + JSON.stringify(d, 4));
|
|
||||||
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 {
|
|
||||||
//console.log("SELECT coreId, published_at FROM Alerts WHERE coreId = '" + coreId + "' ORDER BY published_at DESC LIMIT 30;");
|
|
||||||
//console.log(rows);
|
|
||||||
|
|
||||||
// Loop over elements in rows array, convert ugly UTC times to pretty local times.
|
|
||||||
rows.forEach(function(row){
|
|
||||||
row.pubDate = courtsopenUtils.getLocDateFromUTC(row.published_at);
|
|
||||||
row.pubTime = courtsopenUtils.getLocTimeFromUTC(row.published_at);
|
|
||||||
if(row.status.toLowerCase().indexOf('alert') > -1){
|
|
||||||
row.rowClass = 'alert-row';
|
|
||||||
} else { row.rowClass = 'non-alert-row'; }
|
|
||||||
});
|
|
||||||
|
|
||||||
res.render('core', {alerts: rows}, function(err, html) {
|
|
||||||
res.send(html);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.post('/', function(req, res){
|
app.post('/', function(req, res){
|
||||||
var postEvent = req.body.postEvent;
|
var postEvent = req.body.postEvent;
|
||||||
var source = req.body.source;
|
var source = req.body.source;
|
||||||
|
Loading…
Reference in New Issue
Block a user