diff --git a/endpoints/flight/index.js b/endpoints/flight/index.js index cc02c9cd..d04d65e1 100644 --- a/endpoints/flight/index.js +++ b/endpoints/flight/index.js @@ -37,21 +37,37 @@ app.get('/flight', function(req, res){ var obj = { results: []}; - var fields = ['date','flightNumber','to','plannedArrival','realArrival','status']; + var fields = ['date','flightNumber','airline','to','plannedArrival','realArrival','status']; data.find('table tr').each(function(key){ if(key !== 0){ - var flight = { - 'date': '', - 'flightNumber':'', - 'to': '', - 'plannedArrival': '', - 'realArrival': '', - 'status': '' + var flight = {}; + if(data.type === 'departures') { + flight = { + 'date': '', + 'flightNumber':'', + 'airline':'', + 'to': '', + 'plannedArrival': '', + 'realArrival': '', + 'status': '' + } + } + else { + flight = { + 'date': '', + 'flightNumber':'', + 'airline':'', + 'from': '', + 'plannedArrival': '', + 'realArrival': '', + 'status': '' + } } + $(this).find('td').each(function(key){ var val = $(this).html(); - if(val != '' && val != 0){ //Perform check and add to car array if it passes + if(val != '' && val != 0){ // Perform check and add to flight array if it passes flight[fields[key]] = val; } @@ -62,4 +78,4 @@ app.get('/flight', function(req, res){ return res.cache(3600).json(obj); }); -}); \ No newline at end of file +}); diff --git a/endpoints/flight/tests/integration_test.js b/endpoints/flight/tests/integration_test.js index 328b6ac7..48e753ce 100644 --- a/endpoints/flight/tests/integration_test.js +++ b/endpoints/flight/tests/integration_test.js @@ -4,7 +4,7 @@ var helpers = require('../../../lib/test_helpers.js'); describe('flight', function() { it("should return an array of objects containing correct fields", function(done) { - var fieldsToCheckFor = ["date","flightNumber","to","plannedArrival","realArrival","status"]; + var fieldsToCheckFor = ["date","flightNumber","airline","to","plannedArrival","realArrival","status"]; var params = helpers.testRequestParams("/flight", { language: "en", type: "departures" diff --git a/test/integration/endpoints.js b/test/integration/endpoints.js index a6071d1d..3abbf950 100644 --- a/test/integration/endpoints.js +++ b/test/integration/endpoints.js @@ -24,4 +24,4 @@ describe('endpoint', function() { done(); }); }); -}); \ No newline at end of file +});