tripstorekrabi-shared 1.21.4 → 1.21.6

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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/price.js +10 -10
  3. package/utils.js +11 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tripstorekrabi-shared",
3
- "version": "1.21.4",
3
+ "version": "1.21.6",
4
4
  "description": "Shared library for Trip Store Krabi",
5
5
  "author": "Stefan Sommer <tonprince@gmail.com>",
6
6
  "repository": {
package/price.js CHANGED
@@ -1,4 +1,4 @@
1
- import { CUSTOM_MEETING_POINT, TELL_HOTEL_LATER_STARTING_POINT, getBookingType } from "./utils.js";
1
+ import { CUSTOM_MEETING_POINT, TELL_HOTEL_LATER_STARTING_POINT, getBookingSourceKey } from "./utils.js";
2
2
  import dayjs from 'dayjs';
3
3
  import isBetween from 'dayjs/plugin/isBetween.js';
4
4
 
@@ -68,13 +68,13 @@ function calculateProductPrice(booking, pricing, options = { mode: SELLING_MODE
68
68
  console.error(`No volume price found for the total amount of ${booking.adults + booking.children} people`);
69
69
  return undefined;
70
70
  } else {
71
- let bookingType = getBookingType(booking.referenceNumber);
71
+ let bookingSourceKey = getBookingSourceKey(booking.otaPartnerRef);
72
72
 
73
- if (volume[bookingType]) {
74
- let customPricing = volume[bookingType];
73
+ if (volume[bookingSourceKey]) {
74
+ let customPricing = volume[bookingSourceKey];
75
75
 
76
76
  if (options.mode === SELLING_MODE) {
77
- let commissionRate = pricing.commissionRates?.[bookingType];
77
+ let commissionRate = pricing.commissionRates?.[bookingSourceKey];
78
78
 
79
79
  if (commissionRate && commissionRate > 0) {
80
80
  total = booking.adults * calculateSellingPrice(commissionRate, customPricing.adult.partnerNetPrice) + (pricing.ageBands.child.active && volume.child && booking.children ? (booking.children * calculateSellingPrice(commissionRate, customPricing.child.partnerNetPrice)) : 0);
@@ -102,13 +102,13 @@ function calculateProductPrice(booking, pricing, options = { mode: SELLING_MODE
102
102
  console.error(`No volume price found for the total amount of ${booking.adults + booking.children} people`);
103
103
  return undefined;
104
104
  } else {
105
- let bookingType = getBookingType(booking.referenceNumber);
105
+ let bookingSourceKey = getBookingSourceKey(booking.otaPartnerRef);
106
106
 
107
- if (volume[bookingType]) {
108
- let customPricing = volume[bookingType];
107
+ if (volume[bookingSourceKey]) {
108
+ let customPricing = volume[bookingSourceKey];
109
109
 
110
110
  if (options.mode === SELLING_MODE) {
111
- let commissionRate = pricing.commissionRates?.[bookingType];
111
+ let commissionRate = pricing.commissionRates?.[bookingSourceKey];
112
112
 
113
113
  if (commissionRate && commissionRate > 0) {
114
114
  total = calculateSellingPrice(commissionRate, customPricing.partnerNetPrice);
@@ -139,7 +139,7 @@ function calculateProductPrice(booking, pricing, options = { mode: SELLING_MODE
139
139
  }
140
140
 
141
141
  export function findVolume(people, pricing) {
142
- let total = people.adults + people.children ?? 0;
142
+ let total = (people.adults ?? 0) + (people.children ?? 0);
143
143
  return [...pricing.volumes].sort((v1, v2) => v1.max - v2.max).find((item, i) => {
144
144
  if (total <= item.max) {
145
145
  return true;
package/utils.js CHANGED
@@ -730,26 +730,24 @@ export function isTSKBooking(otaPartnerRef) {
730
730
  return !otaPartnerRef || otaPartnerRef.id === TRIPSTORE_AGENCY_ID;
731
731
  }
732
732
 
733
- export function getBookingType(referenceNumber) {
734
- if (!referenceNumber) {
735
- return '';
736
- }
737
-
738
- if (isGYGBooking(referenceNumber)) {
733
+ export function getBookingSourceKey(otaPartnerRef) {
734
+ if (isGYGBooking(otaPartnerRef)) {
739
735
  return 'gyg';
740
- } else if (isViatorBooking(referenceNumber)) {
736
+ } else if (isViatorBooking(otaPartnerRef)) {
741
737
  return 'br';
742
- } else if (isExpediaBooking(referenceNumber)) {
738
+ } else if (isExpediaBooking(otaPartnerRef)) {
743
739
  return 'exp';
744
- } else if (isKlookBooking(referenceNumber)) {
740
+ } else if (isKlookBooking(otaPartnerRef)) {
745
741
  return 'klk';
746
- } else if (isMusementBooking(referenceNumber)) {
742
+ } else if (isMusementBooking(otaPartnerRef)) {
747
743
  return 'mus';
748
- } else if (isTiqetsBooking(referenceNumber)) {
744
+ } else if (isTiqetsBooking(otaPartnerRef)) {
749
745
  return 'tiq';
750
- } else if (isCuriosidad(referenceNumber)) {
746
+ } else if (isCuriosidad(otaPartnerRef)) {
751
747
  return 'cur';
752
- } else if (isTSKBooking(referenceNumber)) {
748
+ } else if (isCivitatisBooking(otaPartnerRef)) {
749
+ return 'civ';
750
+ } else if (isTSKBooking(otaPartnerRef)) {
753
751
  return 'tsk';
754
752
  }
755
753