uapi-json 1.17.3 → 1.17.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uapi-json",
3
- "version": "1.17.3",
3
+ "version": "1.17.4",
4
4
  "description": "Travelport Universal API",
5
5
  "main": "src/",
6
6
  "files": [
@@ -585,9 +585,8 @@ function getTicketFromEtr(etr, obj, allowNoProviderLocatorCodeRetrieval = false)
585
585
  const exchangedTickets = [];
586
586
 
587
587
  const allCoupons = ticketsList.map((ticket) => {
588
- return Object.entries(ticket['air:Coupon']).map(([couponKey, coupon]) => {
588
+ return Object.values(ticket['air:Coupon']).map((coupon) => {
589
589
  return {
590
- key: couponKey,
591
590
  ticketNumber: ticket.TicketNumber,
592
591
  couponNumber: coupon.CouponNumber,
593
592
  from: coupon.Origin,
@@ -607,59 +606,54 @@ function getTicketFromEtr(etr, obj, allowNoProviderLocatorCodeRetrieval = false)
607
606
  return all.concat(nextChunk);
608
607
  }, []);
609
608
 
610
- const tickets = ticketsList.map(
611
- (ticket) => {
612
- if (ticket['air:ExchangedTicketInfo']) {
613
- ticket['air:ExchangedTicketInfo'].forEach(
614
- (t) => exchangedTickets.push(t.Number)
615
- );
616
- }
609
+ // Filling exchanged tickets array
610
+ ticketsList.forEach((ticket) => {
611
+ if (ticket['air:ExchangedTicketInfo']) {
612
+ ticket['air:ExchangedTicketInfo'].forEach(
613
+ (t) => exchangedTickets.push(t.Number)
614
+ );
615
+ }
616
+ });
617
617
 
618
- const coupons = Object.keys(ticket['air:Coupon']).map(
619
- (couponKey) => {
620
- const allCouponsIndex = allCoupons.findIndex((ac) => ac.key === couponKey);
621
- const coupon = allCoupons[allCouponsIndex];
622
- const nextCoupon = allCoupons[allCouponsIndex + 1];
623
-
624
- let bookingInfo = null;
625
- // looking for fareInfo by it's fareBasis
626
- // and for bookingInfo by correct FareInfoRef
627
- if (airPricingInfo && airPricingInfo['air:FareInfo']) {
628
- Object.keys(airPricingInfo['air:FareInfo']).forEach(
629
- (fareKey) => {
630
- const fare = airPricingInfo['air:FareInfo'][fareKey];
631
- if (fare.FareBasis === coupon.FareBasis
632
- && airPricingInfo['air:BookingInfo']) {
633
- const bInfo = airPricingInfo['air:BookingInfo'].find(
634
- (info) => info.FareInfoRef === fareKey
635
- );
636
-
637
- if (bInfo) {
638
- bookingInfo = bInfo;
639
- }
640
- }
641
- }
618
+ // Getting ticket coupons
619
+ const ticketsObject = allCoupons.reduce((acc, coupon, index) => {
620
+ const { ticketNumber } = coupon;
621
+ const ticket = acc[ticketNumber] || { ticketNumber, coupons: [] };
622
+ const { coupons } = ticket;
623
+ const nextCoupon = allCoupons[index + 1];
624
+
625
+ let bookingInfo = null;
626
+ // looking for fareInfo by it's fareBasis
627
+ // and for bookingInfo by correct FareInfoRef
628
+ if (airPricingInfo && airPricingInfo['air:FareInfo']) {
629
+ Object.keys(airPricingInfo['air:FareInfo']).forEach(
630
+ (fareKey) => {
631
+ const fare = airPricingInfo['air:FareInfo'][fareKey];
632
+ if (fare.FareBasis === coupon.FareBasis && airPricingInfo['air:BookingInfo']) {
633
+ const bInfo = airPricingInfo['air:BookingInfo'].find(
634
+ (info) => info.FareInfoRef === fareKey
642
635
  );
643
- }
644
636
 
645
- return {
646
- ...coupon,
647
- stopover: (
648
- nextCoupon
649
- ? nextCoupon.stopover
650
- : true
651
- ),
652
- ...(bookingInfo !== null ? { serviceClass: bookingInfo.CabinClass } : null)
653
- };
637
+ if (bInfo) {
638
+ bookingInfo = bInfo;
639
+ }
640
+ }
654
641
  }
655
642
  );
656
-
657
- return {
658
- ticketNumber: ticket.TicketNumber,
659
- coupons,
660
- };
661
643
  }
662
- );
644
+ const couponData = {
645
+ ...coupon,
646
+ stopover: (
647
+ nextCoupon
648
+ ? nextCoupon.stopover
649
+ : true
650
+ ),
651
+ ...(bookingInfo !== null ? { serviceClass: bookingInfo.CabinClass } : null)
652
+ };
653
+ return { ...acc, [ticketNumber]: { ...ticket, coupons: [...coupons, couponData] } };
654
+ }, {});
655
+
656
+ const tickets = Object.values(ticketsObject);
663
657
 
664
658
  const taxes = (airPricingInfo && airPricingInfo['air:TaxInfo'])
665
659
  ? Object.keys(airPricingInfo['air:TaxInfo']).map(