tripstorekrabi-shared 1.20.3 → 1.20.5

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/ota.js +24 -0
  2. package/package.json +4 -3
  3. package/price.js +2 -2
package/ota.js ADDED
@@ -0,0 +1,24 @@
1
+ export function isCommissionable(operatorId, booking, otas) {
2
+ let ota = otas.find((item) => booking.referenceNumber.startsWith(item.bookingPrefix));
3
+
4
+ // stop checking if it's not an OTA booking
5
+ if (ota === undefined) {
6
+ return false;
7
+ }
8
+
9
+ // find the account associated with the operator
10
+ let account = (ota.accounts ?? []).find(
11
+ (account) =>
12
+ account.operators.find((item) => item.id === operatorId) &&
13
+ (!booking.gygSupplierId || booking.gygSupplierId === account.gygSupplierId)
14
+ );
15
+
16
+ // find the default account where all operators apply
17
+ if (!account) {
18
+ account = ((ota ?? {}).accounts ?? []).find(
19
+ (account) => (account.operators ?? []).length === 0
20
+ );
21
+ }
22
+
23
+ return account?.commissionable ?? true;
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tripstorekrabi-shared",
3
- "version": "1.20.3",
3
+ "version": "1.20.5",
4
4
  "description": "Shared library for Trip Store Krabi",
5
5
  "author": "Stefan Sommer <tonprince@gmail.com>",
6
6
  "repository": {
@@ -12,11 +12,12 @@
12
12
  "./price": "./price.js",
13
13
  "./availability": "./availability.js",
14
14
  "./booking": "./booking.js",
15
- "./product": "./product.js"
15
+ "./product": "./product.js",
16
+ "./ota": "./ota.js"
16
17
  },
17
18
  "dependencies": {
18
19
  "dayjs": "^1.11.13",
19
- "libphonenumber-js": "^1.12.8",
20
+ "libphonenumber-js": "^1.12.12",
20
21
  "nanoid": "^5.1.5"
21
22
  },
22
23
  "scripts": {
package/price.js CHANGED
@@ -384,9 +384,9 @@ function calculateStartEndPointPrice(people, startEndPoint, options = { mode: SE
384
384
  let isSelling = options.mode in [SELLING_MODE, PARTNER_MODE];
385
385
  if (pricing) {
386
386
  if (pricing.type === "group") {
387
- return (isSelling ? pricing.sellingPrice : pricing.operatorNetPrice) * Math.ceil((people.adults + people.children) / pricing.max);
387
+ return (isSelling ? (pricing.sellingPrice ?? pricing.amount) : pricing.operatorNetPrice) * Math.ceil((people.adults + people.children) / pricing.max);
388
388
  } else if (pricing.type === "person") {
389
- return (isSelling ? pricing.sellingPrice : pricing.operatorNetPrice) * (people.adults + people.children);
389
+ return (isSelling ? (pricing.sellingPrice ?? pricing.amount) : pricing.operatorNetPrice) * (people.adults + people.children);
390
390
  } else {
391
391
  return 0;
392
392
  }