Skip to content

Commit

Permalink
Merge pull request #31 from TourConnect/fix/catch_error
Browse files Browse the repository at this point in the history
Remove deprecated searchQuote method and enhance error handling in ad…
  • Loading branch information
mogii authored Jan 21, 2025
2 parents 7862d7a + 5fde943 commit ffc2e70
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 235 deletions.
78 changes: 0 additions & 78 deletions __snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3305,84 +3305,6 @@ exports[`search tests searchItineraries 1`] = `
Object {
"bookings": Array [
Object {
"AccountingDetails": Object {
"AmountDue": 0,
"CreditsTotal": 0,
"FutureBilling": 187795,
"InvoicedTotal": 0,
"ReceivedTotal": 0,
},
"AgentRef": "2356674/1",
"BookingId": 316559,
"BookingStatus": "Quotation",
"BookingType": "F",
"BookingUpdateCount": 2,
"CanAddServices": "Y",
"CanCancel": "Y",
"Consult": "",
"Currency": "GBP",
"Dialogue": "",
"Email": "",
"EnteredDate": "2024-09-12",
"IsInternetBooking": "Y",
"Name": "2356674/1 Sean Conta",
"QB": "Q",
"ReadOnly": "N",
"Ref": "ALFI393706",
"Remarks": "",
"Services": Array [
Object {
"CanAccept": "N",
"CanUpdate": "N",
"CancelDeleteStatus": "D",
"Comment": "Deluxe King Room",
"CostedInBooking": "Y",
"Date": "2025-08-13",
"Description": "Bed and Full Buffet Breakfast",
"LinePrice": 187795,
"LocationCode": "LON",
"Opt": "LONHOSANLONBFBDLX",
"OptionNumber": 77490,
"Remarks": "Passenger Notes: NA.
Service Notes: NA.",
"RoomConfigs": Object {
"RoomConfig": Object {
"Adults": 1,
"Children": 0,
"Infants": 0,
"PaxList": Object {
"PaxDetails": Object {
"Forename": "Sean",
"PaxType": "A",
"PersonId": 628199,
"Surname": "Conta",
"Title": "Mr",
},
},
"RoomType": "DB",
},
},
"SCU": "night",
"SCUqty": 4,
"SequenceNumber": 10,
"ServiceExtras": Object {
"ServiceExtra": Object {
"ChargeBasis": "Room",
"Description": "Extra Bed",
"IsCompulsory": "N",
"IsPricePerPerson": "N",
"Quantity": 1,
"SequenceNumber": 1,
},
},
"ServiceLineId": 745684,
"ServiceLineUpdateCount": 1,
"SupplierName": "Sanderson",
"paxList": Array [],
},
],
"TotalPrice": 187795,
"TravelDate": "2025-08-13",
"agentRef": "2356674/1",
"bookingId": "316559",
"bookingStatus": "Quotation",
Expand Down
176 changes: 19 additions & 157 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,124 +659,6 @@ class BuyerPlugin {
};
}


// TODO: safe to deprecate 7-14 days after release date
async searchQuote({
axios,
token: {
hostConnectEndpoint,
hostConnectAgentID,
hostConnectAgentPassword,
},
payload: {
quoteName,
rateId,
quoteId,
// existingQuoteId,
// existingLineId,
optionId,
startDate,
reference,
/*
paxConfigs: [{ roomType: 'DB', adults: 2 }, { roomType: 'TW', children: 2 }]
*/
paxConfigs,
/*
The number of second charge units required (second charge units are discussed
in the OptionInfo section). Should only be specified for options that have SCUs.
Defaults to 1.
*/
chargeUnitQuanity,
extras,
puInfo,
doInfo,
notes,
QB,
directHeaderPayload,
directLinePayload,
customFieldValues = [],
},
}) {
const cfvPerService = customFieldValues.filter(f => f.isPerService && f.value)
.reduce((acc, f) => {
if (f.type === 'extended-option') {
acc[f.id] = f.value.value || f.value;
} else {
acc[f.id] = f.value;
}
return acc;
}, {});
const model = {
AddServiceRequest: {
AgentID: hostConnectAgentID,
Password: hostConnectAgentPassword,
...(quoteId ? {
ExistingBookingInfo: { BookingId: quoteId },
} : {
NewBookingInfo: {
Name: this.escapeInvalidXmlChars(quoteName),
QB: QB || 'Q',
...(directHeaderPayload || {}),
},
}),
...(puInfo && (puInfo.time || puInfo.location || puInfo.flightDetails) ? {
...(puInfo.time && puInfo.time.replace(/\D/g, '') ? {
puTime: puInfo.time.replace(/\D/g, ''),
} : {}),
puRemark: this.escapeInvalidXmlChars(`${puInfo.location ? `Location: ${puInfo.location || 'NA'},` : ''}
${puInfo.flightDetails ? `Flight: ${puInfo.flightDetails || 'NA'},` : ''}
`),
} : {}),
...(doInfo && (doInfo.time || doInfo.location || doInfo.flightDetails) ? {
// only get numbers from doInfo.time
...(doInfo.time && doInfo.time.replace(/\D/g, '') ? {
doTime: doInfo.time.replace(/\D/g, ''),
} : {}),
doRemark: this.escapeInvalidXmlChars(`${doInfo.location ? `Location: ${doInfo.location || 'NA'},` : ''}
${doInfo.flightDetails ? `Flight: ${doInfo.flightDetails || 'NA'},` : ''}
`),
} : {}),
...(extras && extras.filter(e => e.selectedExtra && e.selectedExtra.id).length ? {
ExtraQuantities: {
ExtraQuantityItem: extras.filter(e => e.selectedExtra && e.selectedExtra.id).map(e => ({
SequenceNumber: e.selectedExtra.id,
ExtraQuantity: e.quantity,
})),
},
} : {}),
Remarks: this.escapeInvalidXmlChars(notes).slice(0, 220),
Opt: optionId,
DateFrom: startDate,
RateId: rateId || 'Default',
SCUqty: (() => {
const num = parseInt(chargeUnitQuanity, 10);
if (isNaN(num) || num < 1) return 1;
return num;
})(),
AgentRef: reference,
RoomConfigs: this.getRoomConfigs(paxConfigs),
...(directLinePayload || {}),
...(cfvPerService || {}),
},
};
const replyObj = await this.callTourplan({
model,
endpoint: hostConnectEndpoint,
axios,
xmlOptions: hostConnectXmlOptions,
});
return {
message: R.path(['AddServiceReply', 'Status'], replyObj)
=== 'NO' ? 'Service cannot be added to quote for the requested date/stay. (e.g. no rates, block out period, on request, minimum stay etc.)' : '',
quote: {
id: R.path(['AddServiceReply', 'BookingId'], replyObj) || quoteId,
reference: R.path(['AddServiceReply', 'Ref'], replyObj),
linePrice: R.path(['AddServiceReply', 'Services', 'Service', 'LinePrice'], replyObj),
lineId: R.path(['AddServiceReply', 'ServiceLineId'], replyObj),
},
};
}

async addServiceToItinerary({
axios,
token: {
Expand Down Expand Up @@ -1008,47 +890,27 @@ class BuyerPlugin {
const replyObjs = await Promise.all(allSearches);
const bookingHeaders = R.flatten(replyObjs.map(o => R.pathOr([], ['ListBookingsReply', 'BookingHeaders', 'BookingHeader'], o)));
const bookings = await Promise.map(bookingHeaders, async bookingHeader => {
const getBookingPayload = getPayload('GetBookingRequest', {
BookingId: R.prop('BookingId', bookingHeader),
ReturnAccountInfo: 'Y',
ReturnRoomConfigs: 'Y',
});
const bookingReply = await this.callTourplan(getBookingPayload);
const booking = R.path(['GetBookingReply'], bookingReply);
const newBooking = await translateItineraryBooking({
rootValue: booking,
typeDefs: itineraryBookingTypeDefs,
query: itineraryBookingQuery,
});
// TODO: safe to deprecate 7-14 days after release date
let Services = R.pathOr([], ['Services', 'Service'], booking);
if (!Array.isArray(Services)) Services = [Services];
Services = Services.map(s => {
let actualRoomConfigs = s.RoomConfigs.RoomConfig;
if (!Array.isArray(actualRoomConfigs)) actualRoomConfigs = [actualRoomConfigs];
const paxList = actualRoomConfigs.reduce((acc, roomConfig) => {
const paxDetails = R.pathOr([], ['PaxList', 'PaxDetails'], roomConfig);
if (!Array.isArray(paxDetails)) return acc;
return [...acc, ...paxDetails];
}, [])
.map(p => ({
personId: R.path(['PersonId'], p),
firstName: R.path(['Forename'], p),
lastName: R.path(['Surname'], p),
}));
return {
...s,
paxList,
};
});
return {
...newBooking,
...booking,
Services,
};
try {
const getBookingPayload = getPayload('GetBookingRequest', {
BookingId: R.prop('BookingId', bookingHeader),
ReturnAccountInfo: 'Y',
ReturnRoomConfigs: 'Y',
});
const bookingReply = await this.callTourplan(getBookingPayload);
const booking = R.path(['GetBookingReply'], bookingReply);
const newBooking = await translateItineraryBooking({
rootValue: booking,
typeDefs: itineraryBookingTypeDefs,
query: itineraryBookingQuery,
});
return newBooking;
} catch (err) {
console.log('error in searchBooking', err);
return null;
}
}, { concurrency: 10 });
return {
bookings,
bookings: bookings.filter(b => b),
};
}
}
Expand Down

0 comments on commit ffc2e70

Please sign in to comment.