tripstorekrabi-shared 1.23.0 → 1.23.2

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/booking.js +37 -6
  2. package/package.json +2 -2
package/booking.js CHANGED
@@ -362,11 +362,42 @@ export function getStartingPointMessage(booking, product, options = { compact: f
362
362
  return text;
363
363
  }
364
364
 
365
- export function hasFood(product) {
366
- return (product.includes ?? []).find((item) => {
367
- item = item.toLowerCase();
368
- return item.includes('breakfast') || item.includes('lunch') || item.includes('brunch') || item.includes('dinner') || item.includes('snacks');
369
- }) != null;
365
+ export function requiresDietaryInfo(booking, product) {
366
+ if (!product) return true;
367
+
368
+ const mainIsFood = hasFood(product);
369
+
370
+ const foodAddOnsInBooking =
371
+ booking?.addOns?.filter((bAddOn) => {
372
+ const productAddOn = product.addOns?.find((pAddOn) => pAddOn.id === bAddOn.id);
373
+ return productAddOn && hasFood(productAddOn.title);
374
+ }) || [];
375
+
376
+ const hasFoodAddOnWithPax = foodAddOnsInBooking.some((bAddOn) => {
377
+ return (bAddOn.adults || 0) + (bAddOn.children || 0) > 0;
378
+ });
379
+
380
+ if (foodAddOnsInBooking.length > 0) {
381
+ return hasFoodAddOnWithPax;
382
+ }
383
+
384
+ return mainIsFood;
385
+ }
386
+
387
+ export function hasFood(input) {
388
+ if (!input) return false;
389
+
390
+ const items = [input].flat().map(item => {
391
+ if (typeof item === 'string') return item;
392
+ return item?.title || item?.name || '';
393
+ });
394
+
395
+ const foodKeywords = ['breakfast', 'lunch', 'brunch', 'dinner', 'snacks'];
396
+
397
+ return items.some(item => {
398
+ const lowerItem = item.toLowerCase();
399
+ return foodKeywords.some(keyword => lowerItem.includes(keyword));
400
+ });
370
401
  }
371
402
 
372
403
  export function createTodos(booking, product) {
@@ -408,7 +439,7 @@ export function createTodos(booking, product) {
408
439
  }
409
440
  }
410
441
 
411
- if (product && hasFood(product)) {
442
+ if (product && requiresDietaryInfo(booking, product)) {
412
443
  if (!booking.dietary) {
413
444
  todos.dietary = "missing";
414
445
  } else if (!booking.dietaryConfirmed && booking.dietary?.length > 0 && booking.dietary !== 'None' && booking.sentToOperator === true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tripstorekrabi-shared",
3
- "version": "1.23.0",
3
+ "version": "1.23.2",
4
4
  "description": "Shared library for Trip Store Krabi",
5
5
  "author": "Stefan Sommer <tonprince@gmail.com>",
6
6
  "repository": {
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "dayjs": "^1.11.19",
21
- "libphonenumber-js": "^1.12.33",
21
+ "libphonenumber-js": "^1.12.36",
22
22
  "nanoid": "^5.1.6"
23
23
  },
24
24
  "scripts": {