Skip to content

Commit b29d34d

Browse files
committed
(feat) GET search route gets all flights and returns data, but does not filter for relevancy.
1 parent a6bbedb commit b29d34d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

controllerHelpers/thirdPartyApiHelpers.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ var callFlightApi = function( endpoint ) {
1818
return deferred.promise;
1919
};
2020

21+
var createFlightSearchUrl = function( airlineCode, from, to, date ) {
22+
return 'flight_search/' + airlineCode + '?date=' + date + '&from=' + from + '&to=' + to;
23+
};
24+
2125
exports.getAirlines = function() {
2226
return callFlightApi( 'airlines' );
2327
};
@@ -33,4 +37,22 @@ exports.getAirports = function( request ) {
3337
return airports;
3438
});
3539
}
40+
};
41+
42+
exports.searchForFlight = function( from, to, date ) {
43+
return exports.getAirlines()
44+
.then(function( airlines ) {
45+
airlines = JSON.parse( airlines );
46+
// for each airline, make request for dates
47+
var requests = [];
48+
49+
var numberOfAirlines = airlines.length;
50+
for ( var i = 0; i < numberOfAirlines; i++ ) {
51+
var airline = airlines[ i ];
52+
var url = createFlightSearchUrl( airline.code, from, to, date );
53+
requests.push( callFlightApi( url ) );
54+
}
55+
56+
return Q.all( requests );
57+
});
3658
};

routes/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ router.get('/search', function( req, res, next ) {
4848
next( err );
4949
}
5050
}, function( req, res ) {
51-
thirdPartyHelpers.searchForFlight( req.query.to, req.query.from, req.query.date )
51+
thirdPartyHelpers.searchForFlight( req.query.from, req.query.to, req.query.date )
5252
.then(function( matchingFlights ) {
5353
res.send( matchingFlights );
5454
})

0 commit comments

Comments
 (0)