tripstorekrabi-shared 1.23.1 → 1.23.3

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 +25 -18
  2. package/package.json +1 -1
package/booking.js CHANGED
@@ -367,31 +367,38 @@ export function requiresDietaryInfo(booking, product) {
367
367
 
368
368
  const mainIsFood = hasFood(product);
369
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);
374
- }) || [];
375
-
376
- const hasFoodAddOnWithPax = foodAddOnsInBooking.some((bAddOn) => {
377
- return (bAddOn.adults || 0) + (bAddOn.children || 0) > 0;
378
- });
370
+ const productFoodAddOns = (product.addOns || []).filter(pAddOn => hasFood(pAddOn));
371
+
372
+ if (productFoodAddOns.length > 0) {
373
+ const hasActiveFoodAddOn = productFoodAddOns.some(pAddOn => {
374
+ const bookedAddOn = booking?.addOns?.find(bAddOn => bAddOn.id === pAddOn.id);
375
+ if (!bookedAddOn) return false;
379
376
 
380
- if (foodAddOnsInBooking.length > 0) {
381
- return hasFoodAddOnWithPax;
377
+ const totalPax = (bookedAddOn.adults || 0) + (bookedAddOn.children || 0);
378
+ return totalPax > 0;
379
+ });
380
+
381
+ return hasActiveFoodAddOn;
382
382
  }
383
383
 
384
384
  return mainIsFood;
385
385
  }
386
386
 
387
- export function hasFood(product) {
388
- return (product.includes ?? []).find((item) => {
389
- item = item.toLowerCase();
390
- return item.includes('breakfast') || item.includes('lunch') || item.includes('brunch') || item.includes('dinner') || item.includes('snacks');
391
- }) != null;
392
- }
387
+ export function hasFood(input) {
388
+ if (!input) return false;
393
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'];
394
396
 
397
+ return items.some(item => {
398
+ const lowerItem = item.toLowerCase();
399
+ return foodKeywords.some(keyword => lowerItem.includes(keyword));
400
+ });
401
+ }
395
402
 
396
403
  export function createTodos(booking, product) {
397
404
  let todos = {};
@@ -432,7 +439,7 @@ export function createTodos(booking, product) {
432
439
  }
433
440
  }
434
441
 
435
- if (product && hasFood(product)) {
442
+ if (product && requiresDietaryInfo(booking, product)) {
436
443
  if (!booking.dietary) {
437
444
  todos.dietary = "missing";
438
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.1",
3
+ "version": "1.23.3",
4
4
  "description": "Shared library for Trip Store Krabi",
5
5
  "author": "Stefan Sommer <tonprince@gmail.com>",
6
6
  "repository": {