tripstorekrabi-shared 1.6.3 → 1.6.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 +4 -4
  3. package/utils.js +4 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tripstorekrabi-shared",
3
- "version": "1.6.3",
3
+ "version": "1.6.6",
4
4
  "description": "Shared library for Trip Store Krabi",
5
5
  "author": "Stefan Sommer",
6
6
  "repository": {
package/price.js CHANGED
@@ -15,9 +15,9 @@ export function calculateProductPrice(booking, pricing, selling = true) {
15
15
  } else {
16
16
  let bookingType = getBookingType(booking.referenceNumber);
17
17
 
18
- if (volume[bookingType]?.active) {
18
+ if (volume[bookingType]) {
19
19
  let customPricing = volume[bookingType];
20
- total = booking.adults * (selling ? customPricing.adult.partnerNetPrice : customPricing.adult.operatorNetPrice) + (pricing.ageBands.child.active && volume.child && booking.children ? booking.children * (selling ? customPricing.child.partnerNetPrice : customPricing.child.operatorNetPrice) : 0);
20
+ total = booking.adults * (selling ? customPricing.adult.partnerNetPrice : customPricing.adult.operatorNetPrice ?? volume.adult.operatorNetPrice) + (pricing.ageBands.child.active && volume.child && booking.children ? booking.children * (selling ? customPricing.child.partnerNetPrice : customPricing.child.operatorNetPrice ?? volume.child.operatorNetPrice) : 0);
21
21
  } else {
22
22
  total = booking.adults * (selling ? volume.adult.sellingPrice : volume.adult.operatorNetPrice) + (pricing.ageBands.child.active && volume.child && booking.children ? booking.children * (selling ? volume.child.sellingPrice : volume.child.operatorNetPrice) : 0);
23
23
  }
@@ -32,9 +32,9 @@ export function calculateProductPrice(booking, pricing, selling = true) {
32
32
  } else {
33
33
  let bookingType = getBookingType(booking.referenceNumber);
34
34
 
35
- if (volume[bookingType]?.active) {
35
+ if (volume[bookingType]) {
36
36
  let customPricing = volume[bookingType];
37
- total = selling ? customPricing.partnerNetPrice : customPricing.operatorNetPrice;
37
+ total = selling ? customPricing.partnerNetPrice : customPricing.operatorNetPrice ?? volume.operatorNetPrice;
38
38
  } else {
39
39
  total = (selling ? volume.sellingPrice : volume.operatorNetPrice);
40
40
  }
package/utils.js CHANGED
@@ -292,16 +292,6 @@ export function isNumeric(n) {
292
292
  return !isNaN(parseFloat(n)) && isFinite(n);
293
293
  }
294
294
 
295
- export function validURL(str) {
296
- var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
297
- '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
298
- '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
299
- '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
300
- '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
301
- '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
302
- return !!pattern.test(str);
303
- }
304
-
305
295
  export function getBookingSummary(booking, options = {}) {
306
296
  let summary = "";
307
297
  if (!options.excludeReferenceNumber) {
@@ -317,7 +307,7 @@ export function getBookingSummary(booking, options = {}) {
317
307
  }
318
308
 
319
309
  if (booking.productDescription && booking.operator && booking.departureDate && booking.schedule && booking.leadTraveller) {
320
- let departureDate = dayjs(booking.departureDate.toDate()).format("DD.MM.YYYY");
310
+ let departureDate = dayjs(booking.departureDate.toDate()).tz("Asia/Bangkok").format("DD.MM.YYYY");
321
311
  summary += booking.productDescription + ", " + departureDate + ", " + booking.operator + ", " + booking.adults + ", " + booking.children + ", "
322
312
  + booking.infants + ", " + booking.leadTraveller;
323
313
 
@@ -448,10 +438,10 @@ export function validatePickupTime(pickupTime, schedule = "", context) {
448
438
  return checkTime(from, departureTime, context);
449
439
  }
450
440
  } else if (pickupTime.indexOf("-") != -1) {
451
- return context.createError({ message: `Invalid pickup time format, use spaces around the dash: ${pickupTime.replace(/ /g, '').replace("-", " - ")}` });
441
+ return context.createError({ message: `Invalid pickup time format, use spaces around the dash: ${pickupTime.replace(/ /g, '').replace("-", " - ")}`, path: context.path, });
452
442
  } else {
453
443
  if (!SCHEDULE_PATTERN.test(pickupTime)) {
454
- return context.createError({ message: "Invalid pickup time format: for example use '09:00' or '08:45 - 09:00'" });
444
+ return context.createError({ message: "Invalid pickup time format: for example use '09:00' or '08:45 - 09:00'", path: context.path, });
455
445
  } else {
456
446
  return checkTime(pickupTime, departureTime, context);
457
447
  }
@@ -470,7 +460,7 @@ function checkTime(pickupTimeValue, departureTimeValue, context) {
470
460
  let departureTimeValues = departureTimeValue.split(":");
471
461
  let departureTime = dayjs().hour(departureTimeValues[0]).minute(departureTimeValues[1]).second(0);
472
462
 
473
- return pickupTime.isSameOrBefore(departureTime) ? true : context.createError({ message: "Pickup time must be before or equals departure time" });
463
+ return pickupTime.isSameOrBefore(departureTime) ? true : context.createError({ message: "Pickup time must be before or equals departure time", path: context.path, });
474
464
  } catch (e) {
475
465
  return false;
476
466
  }