Skip to content

Commit

Permalink
Merge pull request #21 from TourConnect/fix/room_config_error
Browse files Browse the repository at this point in the history
Fix: There should be only one RoomConfigs in each AddService request
  • Loading branch information
shintre authored Aug 24, 2024
2 parents 2d55620 + ab318d9 commit 983c623
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,15 @@ class Plugin {
return R.path(['Reply'], replyObj);
};

this.getPaxConfigs = (paxConfigs, noPaxList) =>
this.getRoomConfigs = (paxConfigs, noPaxList) => {
// There should be only 1 RoomConfigs for AddServiceRequest
let RoomConfigs = {};
// add one RoomConfig for each room required (i.e. one for each PaxConfig)
RoomConfigs.RoomConfig = [];
let indexRoomConfig = 0;
paxConfigs.map(({ roomType, passengers = [] }) => {
const RoomConfig = passengers.reduce((acc, p) => {
const EachRoomConfig = passengers.reduce((acc, p) => {
console.log(JSON.stringify(p));
if (p.passengerType === 'Adult') {
acc.Adults += 1;
}
Expand All @@ -213,13 +219,13 @@ class Plugin {
Quad: 'QD',
Other: 'OT',
})[roomType];
if (RoomType) RoomConfig.RoomType = RoomType;
if (RoomType) EachRoomConfig.RoomType = RoomType;
if (passengers && passengers.length && !noPaxList) {
// There should be only 1 PaxList inside each RoomConfig
RoomConfig.PaxList = {};
// There should be only 1 PaxList inside each EachRoomConfig
EachRoomConfig.PaxList = {};
// Inside PaxList, there should be 1 PaxDetails for each passenger (Pax)
RoomConfig.PaxList.PaxDetails = [];
passengers.forEach((p, index) => {
EachRoomConfig.PaxList.PaxDetails = [];
passengers.forEach((p, indexEachPax) => {
const EachPaxDetails = {
Forename: this.escapeInvalidXmlChars(p.firstName),
Surname: this.escapeInvalidXmlChars(p.lastName),
Expand All @@ -236,11 +242,13 @@ class Plugin {
EachPaxDetails.Age = p.age;
}
}
RoomConfig.PaxList.PaxDetails[index] = EachPaxDetails;
EachRoomConfig.PaxList.PaxDetails[indexEachPax] = EachPaxDetails;
});
}
return { RoomConfig };
RoomConfigs.RoomConfig[indexRoomConfig++] = EachRoomConfig
});
return RoomConfigs;
};
this.escapeInvalidXmlChars = str => {
if (!str) return '';
const convertAccentedChars = s => {
Expand Down Expand Up @@ -546,7 +554,7 @@ class Plugin {
if (isNaN(num) || num < 1) return 1;
return num;
})(),
RoomConfigs: this.getPaxConfigs(paxConfigs, true),
RoomConfigs: this.getRoomConfigs(paxConfigs, true),
AgentID: hostConnectAgentID,
Password: hostConnectAgentPassword,
},
Expand Down Expand Up @@ -714,7 +722,7 @@ class Plugin {
return num;
})(),
AgentRef: reference,
RoomConfigs: this.getPaxConfigs(paxConfigs),
RoomConfigs: this.getRoomConfigs(paxConfigs),
},
};
const replyObj = await this.callTourplan({
Expand Down

0 comments on commit 983c623

Please sign in to comment.