tripstorekrabi-shared 1.1.0 → 1.4.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 (3) hide show
  1. package/package.json +1 -1
  2. package/price.js +2 -2
  3. package/utils.js +8 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tripstorekrabi-shared",
3
- "version": "1.1.0",
3
+ "version": "1.4.0",
4
4
  "description": "Shared library for Trip Store Krabi",
5
5
  "author": "Stefan Sommer",
6
6
  "repository": {
package/price.js CHANGED
@@ -108,11 +108,11 @@ export function calculateStartEndPointPrice(people, startEndPoint, selling = tru
108
108
  }
109
109
 
110
110
  export function findStartingPoint(product, startingPointId, useDefault = true) {
111
- return product.startingPoints.find((item) => item.id === startingPointId) ?? useDefault ? product.startingPoints[0] : null;
111
+ return product.startingPoints.find((item) => item.id === startingPointId) ?? (useDefault ? product.startingPoints[0] : null);
112
112
  }
113
113
 
114
114
  export function findEndPoint(product, endPointId, useDefault = true) {
115
- return product.endPoints.find((item) => item.id === endPointId) ?? useDefault ? product.endPoints[0] ?? { name: "" } : null;
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) {
package/utils.js CHANGED
@@ -404,7 +404,7 @@ export function getItemSummary(item, product) {
404
404
  return summary;
405
405
  }
406
406
 
407
- export function validateSchedule(schedule, schedules = []) {
407
+ export function validateSchedule(schedule, schedules = [], context) {
408
408
  if (schedule === "?") {
409
409
  return true;
410
410
  } else if (schedule.indexOf(" - ") != -1) {
@@ -413,16 +413,19 @@ export function validateSchedule(schedule, schedules = []) {
413
413
  var to = times[1];
414
414
 
415
415
  if (!SCHEDULE_PATTERN.test(from) || !SCHEDULE_PATTERN.test(to) || (from === to)) {
416
- return "Invalid schedule format: for example use '09:00 - 15:30'";
416
+ return context.createError({ message: "Invalid schedule format: for example use '09:00 - 15:30'", path: context.path, });
417
417
  }
418
418
  } else {
419
- return "Invalid schedule format: for example use '09:00 - 15:30'";
419
+ return context.createError({ message: "Invalid schedule format: for example use '09:00 - 15:30'", path: context.path, });
420
420
  }
421
421
 
422
-
423
422
  if (schedule != "") {
424
423
  if (schedules.length > 0 && schedules.indexOf(schedule) == -1) {
425
- return { status: "warning", message: "The value does not match the product schedules" };
424
+ return context.createError({
425
+ message: "The value does not match the product schedules",
426
+ path: context.path,
427
+ params: { status: "warning" },
428
+ });
426
429
  }
427
430
  }
428
431