Skip to content

Commit 72edad3

Browse files
authored
Merge pull request #11 from mtahon/fix/flightSearches
Fixed issue #5 on nested itineraries
2 parents 27bf91b + c3c7e7e commit 72edad3

File tree

6 files changed

+36
-33
lines changed

6 files changed

+36
-33
lines changed

api/v1/searchOffers.js

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const { searchFlight } = require('../../helpers/resolvers/searchFlight');
44

55
module.exports = basicDecorator(async (req, res) => {
66
const { body } = req;
7-
87
let resolver = () => {throw new Error('accommodation or itinerary missing in body');};
98

109
if(body.accommodation) resolver = searchHotel;

helpers/camaroTemplates/hotelAvail.js

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ const hotelAvailTransformTemplate = {
5656
}],
5757
}],
5858
ratePlans: ['/soap:Envelope/soap:Body/OTA_HotelAvailRS/RoomStays/RoomStay/RatePlans/RatePlan', {
59-
_provider_: '#ervmax',
6059
_id_: '@RatePlanCode',
6160
name: '@RatePlanName',
6261
penalties: {

helpers/camaroTemplates/provideAirShopping.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ const provideAirShoppingTransformTemplate = {
1919
itineraryCombinationReference: 'FlightsOverview/FlightRef',
2020
serviceClassReference: 'FlightsOverview/FlightRef/@PriceClassRef',
2121
}],
22-
itineraries: ['/S:Envelope/S:Body/AirShoppingRS/DataLists', {
23-
combinations: ['FlightList/Flight', {
22+
itineraries: {
23+
combinations: ['/S:Envelope/S:Body/AirShoppingRS/DataLists/FlightList/Flight', {
2424
_id_: '@FlightKey',
2525
_items_: 'SegmentReferences',
2626
}],
27-
segments: ['FlightSegmentList/FlightSegment', {
27+
segments: ['/S:Envelope/S:Body/AirShoppingRS/DataLists/FlightSegmentList/FlightSegment', {
2828
_id_: '@SegmentKey',
2929
operator: {
3030
operatorType: '#airline',
@@ -43,7 +43,7 @@ const provideAirShoppingTransformTemplate = {
4343
splittedArrivalTime: 'Arrival/Time',
4444
splittedArrivalDate: 'Arrival/Date',
4545
}],
46-
}],
46+
},
4747
serviceClasses: ['/S:Envelope/S:Body/AirShoppingRS/DataLists/PriceClassList/PriceClass', {
4848
_id_: '@PriceClassID',
4949
name: 'ClassOfService/MarketingName',

helpers/parsers/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ const splitSegments = (combinations) => combinations.map(({_items_, ...others})=
5050
_items_ : _items_.split(' '),
5151
}));
5252

53+
5354
const reduceToObjectByKey = (array) => array
5455
.reduce((segments, { _id_, ...others }) => ({
5556
...segments,
5657
[_id_]: others,
5758
}), {});
5859

60+
5961
const roundCommissionDecimals = (offers) => offers
6062
.map(({price, ...others}) => ({
6163
...others,
@@ -79,7 +81,7 @@ const reduceRoomStays = (_roomStays_ => {
7981
var offers = {}
8082
_roomStays_.forEach(roomStay => {
8183

82-
// Create the accomodation key
84+
// Create the accommodation key
8385
var hotelkey = `${roomStay._provider_}.${roomStay._hotelCode_}`;
8486

8587
// Build the offers by parsing the room rates
@@ -91,7 +93,7 @@ const reduceRoomStays = (_roomStays_ => {
9193
// Reference from other elements
9294
ratePlanReference: roomRate.ratePlanReference,
9395
roomTypeReference: roomRate.roomTypeReference,
94-
accomodationReference: hotelkey,
96+
accommodationReference: hotelkey,
9597

9698
// Build price
9799
price: {

helpers/resolvers/searchFlight.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@ const searchFlight = async (body) => {
3232
if (errors.length) throw new Error(`${errors[0].message}`);
3333

3434
const searchResults = await transform(response.data, provideAirShoppingTransformTemplate);
35-
searchResults.itineraries[0].segments =
36-
mergeHourAndDate(searchResults.itineraries[0].segments, 'splittedDepartureDate', 'splittedDepartureTime', 'departureTime');
37-
searchResults.itineraries[0].segments =
38-
mergeHourAndDate(searchResults.itineraries[0].segments, 'splittedArrivalDate', 'splittedArrivalTime', 'arrivalTime');
39-
searchResults.itineraries[0].segments = reduceToObjectByKey(searchResults.itineraries[0].segments);
35+
searchResults.itineraries.segments =
36+
mergeHourAndDate(searchResults.itineraries.segments, 'splittedDepartureDate', 'splittedDepartureTime', 'departureTime');
37+
searchResults.itineraries.segments =
38+
mergeHourAndDate(searchResults.itineraries.segments, 'splittedArrivalDate', 'splittedArrivalTime', 'arrivalTime');
39+
searchResults.itineraries.segments = reduceToObjectByKey(searchResults.itineraries.segments);
4040

41-
searchResults.itineraries[0].combinations = splitSegments(searchResults.itineraries[0].combinations);
42-
searchResults.itineraries[0].combinations = reduceToObjectByKey(searchResults.itineraries[0].combinations);
43-
searchResults.itineraries[0].combinations = reduceToProperty(searchResults.itineraries[0].combinations, '_items_');
41+
// Walk through the flight list
42+
var combinations = {};
43+
searchResults.itineraries.combinations.forEach(flight => {
44+
combinations[flight._id_] = flight._items_.split(' ');
45+
});
46+
searchResults.itineraries.combinations = combinations;
4447

4548
for (const offer of Object.values(searchResults.offers)) {
4649
offer.offerItems = reduceToObjectByKey(offer.offerItems);

public/wt-aggregator.yaml

+17-17
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ paths:
6161
summary: A search for hotels
6262
value:
6363
{
64-
"accomodation": {
64+
"accommodation": {
6565
"location" : {
6666
"rectangle": {
6767
"south": "50.0929802",
@@ -635,27 +635,27 @@ components:
635635
- train
636636
example: 'flight'
637637

638-
# Defines the list of accomodation types
639-
AccomodationType:
640-
description: Type of accomodation service
638+
# Defines the list of accommodation types
639+
AccommodationType:
640+
description: Type of accommodation service
641641
type: string
642642
maxLength: 24
643643
enum:
644644
- hotel
645645
example: 'hotel'
646646

647-
Accomodation:
648-
description: An accomodation object
647+
Accommodation:
648+
description: An accommodation object
649649
type: object
650650
properties:
651651

652652
name:
653-
description: The name of the property or accomodation
653+
description: The name of the property or accommodation
654654
type: string
655655
example: Comfort Hotel Xpress Stockholm Central
656656

657657
type:
658-
$ref: '#/components/schemas/AccomodationType'
658+
$ref: '#/components/schemas/AccommodationType'
659659

660660
description:
661661
description: The description of the property
@@ -852,7 +852,7 @@ components:
852852
type: string
853853
enum:
854854
- transportation
855-
- accomodation
855+
- accommodation
856856
- lounge
857857
- fasttrack
858858
- parking
@@ -863,7 +863,7 @@ components:
863863
description: The sub-type of service
864864
oneOf:
865865
- $ref: '#/components/schemas/TransportationType'
866-
- $ref: '#/components/schemas/AccomodationType'
866+
- $ref: '#/components/schemas/AccommodationType'
867867
example: 'flight'
868868

869869
# The price of the service
@@ -897,20 +897,20 @@ components:
897897
itinerary:
898898
$ref: '#/components/schemas/Itinerary'
899899

900-
# The option of the accomodation being searched
901-
accomodation:
902-
description: Criteria for the accomodation search
900+
# The option of the accommodation being searched
901+
accommodation:
902+
description: Criteria for the accommodation search
903903
type: object
904904
properties:
905905
location:
906906
$ref: '#/components/schemas/Location'
907907
arrival:
908908
type: string
909-
description: arrival day in the accomodation
909+
description: arrival day in the accommodation
910910
format: datetime
911911
departure:
912912
type: string
913-
description: departure day from the accomodation
913+
description: departure day from the accommodation
914914
format: datetime
915915

916916

@@ -961,11 +961,11 @@ components:
961961
additionalProperties:
962962
$ref: '#/components/schemas/Segment'
963963

964-
accomodations:
964+
accommodations:
965965
description: The acomodations matching an search request
966966
type: object
967967
additionalProperties:
968-
$ref: '#/components/schemas/Accomodation'
968+
$ref: '#/components/schemas/Accommodation'
969969

970970
# The service classes involved in the offer
971971
serviceClasses:

0 commit comments

Comments
 (0)