Exclude trains with false coordinates
This commit is contained in:
@ -25,7 +25,6 @@ exports.getLiveTrainData = functions.https.onRequest((request, response) => {
|
||||
snapshot.forEach(doc => {
|
||||
jsonData.push(doc.data());
|
||||
});
|
||||
// response.send(jsonData);
|
||||
response.json({data: jsonData});
|
||||
})
|
||||
});
|
||||
@ -56,21 +55,25 @@ exports.postLiveTrainData = functions.https.onRequest((request, response) => {
|
||||
batchDelete.commit().then(function() {
|
||||
// batch write all train JSON objects to the "liveTrainData" collection
|
||||
var batchWrite = db.batch();
|
||||
|
||||
jsonData.forEach((doc) => {
|
||||
// ignore trains with longitudes or latitudes equal zero
|
||||
if (!(doc["TrainLongitude"] == 0 || doc["TrainLatitude"] == 0)) {
|
||||
// set the train's code as the document ID
|
||||
var docID = db.collection('liveTrainData').doc(doc["TrainCode"][0]);
|
||||
batchWrite.set(docID, doc);
|
||||
}
|
||||
});
|
||||
|
||||
batchWrite.commit().then(function () {
|
||||
response.send("Successfully fetched and uploaded data from Irish Rail");
|
||||
response.send({data: "Successfully fetched and uploaded data from Irish Rail"});
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
.catch((error) => {;
|
||||
response.send("Error fetching data from the IrishRail API");
|
||||
response.send({data: "Error fetching data from the IrishRail API"});
|
||||
})
|
||||
});
|
||||
})
|
Reference in New Issue
Block a user