tripstorekrabi-shared 1.0.0 → 1.1.0

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 (2) hide show
  1. package/package.json +1 -1
  2. package/price.js +6 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tripstorekrabi-shared",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Shared library for Trip Store Krabi",
5
5
  "author": "Stefan Sommer",
6
6
  "repository": {
package/price.js CHANGED
@@ -66,8 +66,8 @@ export function countMaxPeople(pricing) {
66
66
 
67
67
  export function calculateTotalPrice(data, product, selling = true) {
68
68
  let total = calculateProductPrice(data, product.pricing, selling);
69
- total += calculateStartEndPointPrice(data, findStartingPoint(product, data.startingPointId), selling);
70
- total += calculateStartEndPointPrice(data, findEndPoint(product, data.endPointId), selling);
69
+ total += calculateStartEndPointPrice(data, findStartingPoint(product, data.startingPointId, false), selling);
70
+ total += calculateStartEndPointPrice(data, findEndPoint(product, data.endPointId, false), selling);
71
71
  total += calculateNationalParkFee(data, product);
72
72
  total += calculateAddOnsPrice(data, product, selling);
73
73
  return total;
@@ -107,12 +107,12 @@ export function calculateStartEndPointPrice(people, startEndPoint, selling = tru
107
107
  }
108
108
  }
109
109
 
110
- export function findStartingPoint(product, startingPointId) {
111
- return product.startingPoints.find((item) => item.id === startingPointId) ?? product.startingPoints[0];
110
+ export function findStartingPoint(product, startingPointId, useDefault = true) {
111
+ return product.startingPoints.find((item) => item.id === startingPointId) ?? useDefault ? product.startingPoints[0] : null;
112
112
  }
113
113
 
114
- export function findEndPoint(product, endPointId) {
115
- return product.endPoints.find((item) => item.id === endPointId) ?? product.endPoints[0] ?? { name: "" };
114
+ export function findEndPoint(product, endPointId, useDefault = true) {
115
+ return product.endPoints.find((item) => item.id === endPointId) ?? useDefault ? product.endPoints[0] ?? { name: "" } : null;
116
116
  }
117
117
 
118
118
  export function findAddOn(id, addOns) {