Skip to content

Commit

Permalink
Merge pull request #614 from Travelport-Ukraine/TC-3363
Browse files Browse the repository at this point in the history
TC-3363: correct air/service segments' indexes
  • Loading branch information
dchertousov authored Feb 24, 2023
2 parents b59bc93 + dac82b8 commit 2de2cfe
Show file tree
Hide file tree
Showing 25 changed files with 76 additions and 102 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uapi-json",
"version": "1.14.6",
"version": "1.14.7",
"description": "Travelport Universal API",
"main": "src/",
"files": [
Expand Down Expand Up @@ -32,7 +32,7 @@
"Artem Pylypchuk <[email protected]>",
"Yevhenii Huselietov <[email protected]>",
"Mark Omarov <[email protected]>",
"Oleksii Duvanov <kommandant@web-hata.com>"
"Oleksii Duvanov <colden.aid@gmail.com>"
],
"license": "MIT",
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/Services/Air/AirErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Object.assign(AirParsingError, createErrorsList({
ReservationProviderInfoMissing: 'Can\'t find provider information about reservation',
CancelResponseNotFound: 'Cancel response not found',
InvalidServiceSegmentFormat: 'Service segment format is invalid',
NoProviderSegmentOrder: 'Segment is missing ProviderSegmentOrder field',
}, AirParsingError));

// Runtime errors
Expand Down
82 changes: 27 additions & 55 deletions src/Services/Air/AirFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ const moment = require('moment');
const parsers = require('../../utils/parsers');
const { AirParsingError } = require('./AirErrors');

function ProviderSegmentOrderReducer(acc, { ProviderSegmentOrder }) {
const x = parseInt(ProviderSegmentOrder, 10);
if (x > acc) {
return x;
}
return acc;
}

/**
* getBaggage -- get baggage information from LFS search
* @param baggageAllowance
Expand Down Expand Up @@ -446,6 +438,24 @@ function formatLowFaresSearch(searchRequest, searchResult) {
return fares;
}

const getSegmentsData = segmentsObject => (segmentsObject
? Object.values(segmentsObject)
: null);

const setIndexes = segments => segments.map(
(segment) => {
const { ProviderSegmentOrder: index } = segment;
if (index === undefined) {
throw new AirParsingError.NoProviderSegmentOrder({
segment,
});
}

return { ...segment, index: parseInt(index, 10) };
}
);


/**
* This function used to transform segments and service segments objects
* to arrays. After that this function try to set indexes with same as in
Expand All @@ -459,58 +469,20 @@ function setIndexesForSegments(
segmentsObject = null,
serviceSegmentsObject = null
) {
const segments = segmentsObject
? Object.keys(segmentsObject).map(k => segmentsObject[k])
: null;
const segmentsData = getSegmentsData(segmentsObject);
const serviceSegmentsData = getSegmentsData(serviceSegmentsObject);

const serviceSegments = serviceSegmentsObject
? Object.keys(serviceSegmentsObject).map(k => serviceSegmentsObject[k])
const segments = segmentsData
? setIndexes(segmentsData)
: null;

if (segments === null && serviceSegments === null) {
return { segments, serviceSegments };
}

if (segments !== null && serviceSegments === null) {
const segmentsNew = segments.map((segment, key) => ({
...segment,
index: key + 1,
}));
return { segments: segmentsNew, serviceSegments };
}

if (segments === null && serviceSegments !== null) {
const serviceSegmentsNew = serviceSegments.map(
(segment, key) => ({
...segment,
index: key + 1,
})
);
return { segments, serviceSegments: serviceSegmentsNew };
}

const maxSegmentsSegmentOrder = segments.reduce(ProviderSegmentOrderReducer, 0);
const maxServiceSegmentsSegmentOrder = serviceSegments.reduce(ProviderSegmentOrderReducer, 0);

const maxOrder = Math.max(
maxSegmentsSegmentOrder,
maxServiceSegmentsSegmentOrder
);

const allSegments = [];

for (let i = 1; i <= maxOrder; i += 1) {
segments.forEach(s => (Number(s.ProviderSegmentOrder) === i ? allSegments.push(s) : null));
serviceSegments.forEach(s => (
Number(s.ProviderSegmentOrder) === i ? allSegments.push(s) : null
));
}

const indexedSegments = allSegments.map((s, k) => ({ ...s, index: k + 1 }));
const serviceSegments = serviceSegmentsData
? setIndexes(serviceSegmentsData)
: null;

return {
segments: indexedSegments.filter(s => s.SegmentType === undefined),
serviceSegments: indexedSegments.filter(s => s.SegmentType === 'Service'),
segments,
serviceSegments,
};
}

Expand Down
2 changes: 1 addition & 1 deletion test/FakeResponses/Air/AirCreateReservation.1ADT.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/FakeResponses/Air/AirCreateReservation.2ADT1CNN.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@
<common_v52_0:BookingTravelerRef Key="sKCAU5tBTle0tRWEnxx/rw=="/>
<common_v52_0:BookingTravelerRef Key="8giuKZjGSr24Sm4Ly8AawA=="/>
<common_v52_0:ProviderReservationInfoRef Key="WU0oSYkYS7+fRjrmDy4Otg=="/>
<air:AirSegment Key="sybKtzvtTHm1Nq7P6FxPTw==" Group="0" Carrier="A3" CabinClass="Economy" FlightNumber="967" ProviderCode="1G" Origin="KBP" Destination="ATH" DepartureTime="2016-11-10T18:35:00.000+02:00" ArrivalTime="2016-11-10T21:05:00.000+02:00" TravelTime="150" Distance="921" ClassOfService="P" ETicketability="Yes" Equipment="320" MarriageGroup="1" Status="HK" ChangeOfPlane="false" GuaranteedPaymentCarrier="No" ProviderReservationInfoRef="WU0oSYkYS7+fRjrmDy4Otg==" TravelOrder="1" OptionalServicesIndicator="false" LinkAvailability="true" ElStat="A">
<air:AirSegment Key="sybKtzvtTHm1Nq7P6FxPTw==" Group="0" Carrier="A3" CabinClass="Economy" FlightNumber="967" ProviderCode="1G" Origin="KBP" Destination="ATH" DepartureTime="2016-11-10T18:35:00.000+02:00" ArrivalTime="2016-11-10T21:05:00.000+02:00" TravelTime="150" Distance="921" ClassOfService="P" ETicketability="Yes" Equipment="320" MarriageGroup="1" Status="HK" ChangeOfPlane="false" GuaranteedPaymentCarrier="No" ProviderReservationInfoRef="WU0oSYkYS7+fRjrmDy4Otg==" TravelOrder="1" ProviderSegmentOrder="1" OptionalServicesIndicator="false" LinkAvailability="true" ElStat="A">
<air:FlightDetails Key="DXL1sFlRQeCskvTL8ujUkw==" Origin="KBP" Destination="ATH" DepartureTime="2016-11-10T18:35:00.000+02:00" ArrivalTime="2016-11-10T21:05:00.000+02:00" FlightTime="150" TravelTime="150" Equipment="320" ElStat="C"/>
<common_v52_0:SellMessage>ADD ADVANCE PASSENGER INFORMATION SSRS DOCA/DOCO/DOCS</common_v52_0:SellMessage>
<common_v52_0:SellMessage>PERSONAL DATA WHICH IS PROVIDED TO US IN CONNECTION</common_v52_0:SellMessage>
<common_v52_0:SellMessage>WITH YOUR TRAVEL MAY BE PASSED TO GOVERNMENT AUTHORITIES</common_v52_0:SellMessage>
<common_v52_0:SellMessage>FOR BORDER CONTROL AND AVIATION SECURITY PURPOSES</common_v52_0:SellMessage>
</air:AirSegment>
<air:AirSegment Key="SAJ2rz9GTIKL6+WDYQcF3w==" Group="1" Carrier="A3" CabinClass="Economy" FlightNumber="614" ProviderCode="1G" Origin="ATH" Destination="CDG" DepartureTime="2016-11-11T16:15:00.000+02:00" ArrivalTime="2016-11-11T18:45:00.000+01:00" TravelTime="210" Distance="1306" ClassOfService="P" ETicketability="Yes" Equipment="320" MarriageGroup="1" Status="HK" ChangeOfPlane="false" GuaranteedPaymentCarrier="No" ProviderReservationInfoRef="WU0oSYkYS7+fRjrmDy4Otg==" TravelOrder="2" OptionalServicesIndicator="false" LinkAvailability="true" ElStat="A">
<air:AirSegment Key="SAJ2rz9GTIKL6+WDYQcF3w==" Group="1" Carrier="A3" CabinClass="Economy" FlightNumber="614" ProviderCode="1G" Origin="ATH" Destination="CDG" DepartureTime="2016-11-11T16:15:00.000+02:00" ArrivalTime="2016-11-11T18:45:00.000+01:00" TravelTime="210" Distance="1306" ClassOfService="P" ETicketability="Yes" Equipment="320" MarriageGroup="1" Status="HK" ChangeOfPlane="false" GuaranteedPaymentCarrier="No" ProviderReservationInfoRef="WU0oSYkYS7+fRjrmDy4Otg==" TravelOrder="2" ProviderSegmentOrder="2" OptionalServicesIndicator="false" LinkAvailability="true" ElStat="A">
<air:FlightDetails Key="rti3oOo/SniNfhAB3RhsxQ==" Origin="ATH" Destination="CDG" DepartureTime="2016-11-11T16:15:00.000+02:00" ArrivalTime="2016-11-11T18:45:00.000+01:00" FlightTime="210" TravelTime="210" Equipment="320" DestinationTerminal="1" ElStat="C"/>
<common_v52_0:SellMessage>ARRIVES CDG TERMINAL 1</common_v52_0:SellMessage>
<common_v52_0:SellMessage>ADD ADVANCE PASSENGER INFORMATION SSRS DOCA/DOCO/DOCS</common_v52_0:SellMessage>
Expand Down
Loading

0 comments on commit 2de2cfe

Please sign in to comment.