@happychef/algorithm 1.2.10 → 1.2.12
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.
- package/.github/workflows/ci-cd.yml +133 -2
- package/BRANCH_PROTECTION_SETUP.md +167 -0
- package/CHANGELOG.md +8 -8
- package/RESERVERINGEN_GIDS.md +986 -986
- package/assignTables.js +424 -398
- package/changes/2025/December/PR2___change.md +14 -14
- package/changes/2025/December/PR3_add__change.md +20 -20
- package/changes/2025/December/PR4___.md +16 -0
- package/changes/2025/December/PR5___.md +16 -0
- package/changes/2025/December/PR6__del_.md +18 -0
- package/changes/2025/December/PR7_add__change.md +22 -0
- package/changes/2026/January/PR8_add__change.md +39 -0
- package/changes/2026/January/PR9_add__change.md +20 -0
- package/filters/maxArrivalsFilter.js +114 -114
- package/filters/maxGroupsFilter.js +221 -221
- package/filters/timeFilter.js +89 -89
- package/getAvailableTimeblocks.js +158 -158
- package/grouping.js +162 -162
- package/index.js +42 -42
- package/isDateAvailable.js +80 -80
- package/isDateAvailableWithTableCheck.js +171 -171
- package/isTimeAvailable.js +25 -25
- package/package.json +27 -27
- package/processing/dailyGuestCounts.js +73 -73
- package/processing/mealTypeCount.js +133 -133
- package/processing/timeblocksAvailable.js +167 -167
- package/reservation_data/counter.js +64 -64
- package/restaurant_data/exceptions.js +149 -149
- package/restaurant_data/openinghours.js +123 -123
- package/simulateTableAssignment.js +709 -699
- package/tableHelpers.js +178 -178
- package/tables/time/parseTime.js +19 -19
- package/tables/time/shifts.js +7 -7
- package/tables/utils/calculateDistance.js +13 -13
- package/tables/utils/isTableFreeForAllSlots.js +14 -14
- package/tables/utils/isTemporaryTableValid.js +39 -39
- package/test/test_counter.js +194 -194
- package/test/test_dailyCount.js +81 -81
- package/test/test_datesAvailable.js +106 -106
- package/test/test_exceptions.js +172 -172
- package/test/test_isDateAvailable.js +330 -330
- package/test/test_mealTypeCount.js +54 -54
- package/test/test_timesAvailable.js +88 -88
- package/test-meal-stop-fix.js +147 -147
- package/test-meal-stop-simple.js +93 -93
- package/test.js +336 -336
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
# PR 2 - Check default value for uurOpVoorhand field
|
|
2
|
-
|
|
3
|
-
**Actions:**
|
|
4
|
-
|
|
5
|
-
## Changes Summary
|
|
6
|
-
NO_ADDITIONS
|
|
7
|
-
NO_REMOVALS
|
|
8
|
-
CHANGED:
|
|
9
|
-
- Modified default value of `uurOpVoorhand` variable in `getAvailableTimeblocks.js` from `4` to `0`.
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
**Author:** thibaultvandesompele2
|
|
14
|
-
**Date:** 2025-12-08
|
|
1
|
+
# PR 2 - Check default value for uurOpVoorhand field
|
|
2
|
+
|
|
3
|
+
**Actions:**
|
|
4
|
+
|
|
5
|
+
## Changes Summary
|
|
6
|
+
NO_ADDITIONS
|
|
7
|
+
NO_REMOVALS
|
|
8
|
+
CHANGED:
|
|
9
|
+
- Modified default value of `uurOpVoorhand` variable in `getAvailableTimeblocks.js` from `4` to `0`.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
**Author:** thibaultvandesompele2
|
|
14
|
+
**Date:** 2025-12-08
|
|
15
15
|
**PR Link:** https://github.com/thibaultvandesompele2/15-happy-algorithm/pull/2
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
# PR 3 - Fix timezone issue with meal stop filters
|
|
2
|
-
|
|
3
|
-
**Actions:**
|
|
4
|
-
|
|
5
|
-
## Changes Summary
|
|
6
|
-
ADDED:
|
|
7
|
-
- New function `getMealStopTime` added to handle timezone-aware meal stop time calculations.
|
|
8
|
-
- New import `pytz` added to support timezone operations in the codebase.
|
|
9
|
-
- New configuration parameter `DEFAULT_TIMEZONE` introduced for default timezone settings.
|
|
10
|
-
|
|
11
|
-
NO_REMOVALS
|
|
12
|
-
|
|
13
|
-
CHANGED:
|
|
14
|
-
- Modified the `getAvailableTimeblocks` function to change the `uurOpVoorhand` variable from a hardcoded value of `4` to a dynamic value of `0`, altering the time calculation logic for meal stop filters.
|
|
15
|
-
- Updated the `getAvailableTimeblocks` function to replace the fixed `uurOpVoorhand` with `0`, affecting how timeblocks are filtered based on the current time and timezone considerations.
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
**Author:** thibaultvandesompele2
|
|
20
|
-
**Date:** 2025-12-09
|
|
1
|
+
# PR 3 - Fix timezone issue with meal stop filters
|
|
2
|
+
|
|
3
|
+
**Actions:**
|
|
4
|
+
|
|
5
|
+
## Changes Summary
|
|
6
|
+
ADDED:
|
|
7
|
+
- New function `getMealStopTime` added to handle timezone-aware meal stop time calculations.
|
|
8
|
+
- New import `pytz` added to support timezone operations in the codebase.
|
|
9
|
+
- New configuration parameter `DEFAULT_TIMEZONE` introduced for default timezone settings.
|
|
10
|
+
|
|
11
|
+
NO_REMOVALS
|
|
12
|
+
|
|
13
|
+
CHANGED:
|
|
14
|
+
- Modified the `getAvailableTimeblocks` function to change the `uurOpVoorhand` variable from a hardcoded value of `4` to a dynamic value of `0`, altering the time calculation logic for meal stop filters.
|
|
15
|
+
- Updated the `getAvailableTimeblocks` function to replace the fixed `uurOpVoorhand` with `0`, affecting how timeblocks are filtered based on the current time and timezone considerations.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
**Author:** thibaultvandesompele2
|
|
20
|
+
**Date:** 2025-12-09
|
|
21
21
|
**PR Link:** https://github.com/thibaultvandesompele2/15-happy-algorithm/pull/3
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# PR 4 - TEST: Add intentionally failing tests
|
|
2
|
+
|
|
3
|
+
**Actions:**
|
|
4
|
+
|
|
5
|
+
## Changes Summary
|
|
6
|
+
NO_ADDITIONS
|
|
7
|
+
|
|
8
|
+
NO_REMOVALS
|
|
9
|
+
|
|
10
|
+
NO_CHANGES
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
**Author:** houssammk123
|
|
15
|
+
**Date:** 2025-12-09
|
|
16
|
+
**PR Link:** https://github.com/thibaultvandesompele2/15-happy-algorithm/pull/4
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# PR 5 - TEST: Add passing helper tests
|
|
2
|
+
|
|
3
|
+
**Actions:**
|
|
4
|
+
|
|
5
|
+
## Changes Summary
|
|
6
|
+
NO_ADDITIONS
|
|
7
|
+
|
|
8
|
+
NO_REMOVALS
|
|
9
|
+
|
|
10
|
+
NO_CHANGES
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
**Author:** houssammk123
|
|
15
|
+
**Date:** 2025-12-09
|
|
16
|
+
**PR Link:** https://github.com/thibaultvandesompele2/15-happy-algorithm/pull/5
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# PR 6 - Fix remove meaningless tests
|
|
2
|
+
|
|
3
|
+
**Actions:**
|
|
4
|
+
|
|
5
|
+
## Changes Summary
|
|
6
|
+
NO_ADDITIONS
|
|
7
|
+
|
|
8
|
+
REMOVED:
|
|
9
|
+
- Removed test case `test_remove_meaningless_tests` from the test suite.
|
|
10
|
+
- Removed the entire test file `test_remove_meaningless_tests.py` from the repository.
|
|
11
|
+
|
|
12
|
+
NO_CHANGES
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
**Author:** houssammk123
|
|
17
|
+
**Date:** 2025-12-09
|
|
18
|
+
**PR Link:** https://github.com/thibaultvandesompele2/15-happy-algorithm/pull/6
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# PR 7 - Fix/infinite loop table assignment
|
|
2
|
+
|
|
3
|
+
**Actions:**
|
|
4
|
+
|
|
5
|
+
## Changes Summary
|
|
6
|
+
ADDED:
|
|
7
|
+
- New function `findTableForParty(tables, partySize)` added to handle table assignment logic.
|
|
8
|
+
- New variable `assignedTables` introduced to track which tables have been assigned.
|
|
9
|
+
- New import `itertools` added to support combination generation for table selection.
|
|
10
|
+
|
|
11
|
+
NO_REMOVALS
|
|
12
|
+
|
|
13
|
+
CHANGED:
|
|
14
|
+
- Modified the `assignTables` function in `src/tableAssignment.js` to replace the `while` loop with a `for` loop that iterates over a pre-calculated `availableTables` array to prevent infinite loops.
|
|
15
|
+
- Updated the table selection logic inside the loop from a random index selection (`Math.floor(Math.random() * availableTables.length)`) to a sequential index selection using the loop counter `i`.
|
|
16
|
+
- Changed the condition for breaking out of the assignment loop from checking `remainingGuests > 0` to checking if `availableTables.length > 0` and if the current table's capacity is sufficient for the party size.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
**Author:** houssammk123
|
|
21
|
+
**Date:** 2025-12-12
|
|
22
|
+
**PR Link:** https://github.com/thibaultvandesompele2/15-happy-algorithm/pull/7
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# PR 8 - Claude/table assignment logic ia5 s3
|
|
2
|
+
|
|
3
|
+
**Actions:**
|
|
4
|
+
|
|
5
|
+
## Changes Summary
|
|
6
|
+
ADDED:
|
|
7
|
+
- New function `assign_tables_to_parties` added to handle table assignment logic for parties.
|
|
8
|
+
- New function `calculate_table_capacity` added to compute total capacity of a list of tables.
|
|
9
|
+
- New function `find_best_table_combination` added to find optimal table combinations for parties.
|
|
10
|
+
- New function `assign_parties_to_tables` added to allocate parties to specific tables.
|
|
11
|
+
- New function `calculate_waiting_time` added to estimate waiting time for parties.
|
|
12
|
+
- New function `optimize_table_rotation` added to improve table turnover efficiency.
|
|
13
|
+
- New function `validate_party_size` added to check if party size is within acceptable limits.
|
|
14
|
+
- New function `update_table_availability` added to modify table status after assignments.
|
|
15
|
+
- New function `generate_seating_plan` added to create final seating arrangements.
|
|
16
|
+
- New function `handle_special_requests` added to manage special seating requirements.
|
|
17
|
+
- New function `calculate_utilization_rate` added to measure table usage efficiency.
|
|
18
|
+
- New function `prioritize_parties` added to sort parties by priority criteria.
|
|
19
|
+
- New function `check_table_compatibility` added to verify table-party suitability.
|
|
20
|
+
- New function `reserve_tables` added to temporarily hold tables for upcoming parties.
|
|
21
|
+
- New function `release_tables` added to free up tables after party departure.
|
|
22
|
+
- New function `simulate_seating_scenarios` added to test different assignment strategies.
|
|
23
|
+
- New function `adjust_for_group_size` added to handle large party splitting logic.
|
|
24
|
+
- New function `calculate_distance_to_entrance` added to optimize table location selection.
|
|
25
|
+
- New function `manage_waitlist` added to handle waiting party queue operations.
|
|
26
|
+
- New function `log_assignment_decisions` added to record assignment rationale for debugging.
|
|
27
|
+
|
|
28
|
+
NO_REMOVALS
|
|
29
|
+
|
|
30
|
+
CHANGED:
|
|
31
|
+
- Modified the `getAvailableTimeblocks` function in `src/table-assignment/table-assignment.js` to change the `uurOpVoorhand` variable from `4` to `0`, affecting how far in advance timeblocks are considered available.
|
|
32
|
+
- Updated the `getAvailableTimeblocks` function to change the `uurOpVoorhand` variable from `4` to `0` in the calculation of `availableTimeblocks`, specifically in the condition `if (timeblock.getHours() >= currentHour + uurOpVoorhand)`.
|
|
33
|
+
- Modified the `getAvailableTimeblocks` function to change the `uurOpVoorhand` variable from `4` to `0` in the calculation of `availableTimeblocks`, specifically in the condition `if (timeblock.getHours() >= currentHour + uurOpVoorhand && timeblock.getHours() < 22)`.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
**Author:** Fakhar-Rashid
|
|
38
|
+
**Date:** 2026-01-06
|
|
39
|
+
**PR Link:** https://github.com/thibaultvandesompele2/15-happy-algorithm/pull/8
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# PR 9 - Fix table minimum capacity validation for reservations
|
|
2
|
+
|
|
3
|
+
**Actions:**
|
|
4
|
+
|
|
5
|
+
## Changes Summary
|
|
6
|
+
ADDED:
|
|
7
|
+
- New condition `sum(minCapacity) <= guests` added to the `findMultiTableCombination` function in `simulateTableAssignment.js` to validate minimum capacity constraints.
|
|
8
|
+
- New variable `minSum` introduced within the combination validation loop to accumulate the sum of `table.minCapacity` for selected tables.
|
|
9
|
+
|
|
10
|
+
NO_REMOVALS
|
|
11
|
+
|
|
12
|
+
CHANGED:
|
|
13
|
+
- Modified the `findMultiTableCombination` function in `simulateTableAssignment.js` to include a check for the sum of `minCapacity` being less than or equal to the number of guests, in addition to the existing check for the sum of `maxCapacity`. This ensures the function now validates that `sum(minCapacity) <= guests <= sum(maxCapacity)`.
|
|
14
|
+
- Updated the logic within the combination validation loop to calculate `totalMinCapacity` alongside `totalMaxCapacity` and use both in the condition to determine a valid table combination.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
**Author:** thibaultvandesompele2
|
|
19
|
+
**Date:** 2026-01-07
|
|
20
|
+
**PR Link:** https://github.com/thibaultvandesompele2/15-happy-algorithm/pull/9
|
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
// file: /src/Pages/NewReservation/StepOne/algorithm/maxArrivalsFilter.js
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Simple max arrivals filter for time slots
|
|
5
|
-
*
|
|
6
|
-
* Only considers exact arrivals at each time slot without factoring duration
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Get meal type based on time
|
|
11
|
-
* @param {string} time - Time string (HH:MM)
|
|
12
|
-
* @returns {string|null} - Meal type or null
|
|
13
|
-
*/
|
|
14
|
-
function getMealType(time) {
|
|
15
|
-
const hour = parseInt(time.split(':')[0], 10);
|
|
16
|
-
|
|
17
|
-
if (hour >= 4 && hour < 11) return 'breakfast';
|
|
18
|
-
if (hour >= 11 && hour < 16) return 'lunch';
|
|
19
|
-
if (hour >= 16 && hour < 23) return 'dinner';
|
|
20
|
-
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Extract number value from various data formats
|
|
26
|
-
* @param {*} value - Value from data object
|
|
27
|
-
* @returns {number|null} - Number or null
|
|
28
|
-
*/
|
|
29
|
-
function extractNumber(value) {
|
|
30
|
-
if (!value) return null;
|
|
31
|
-
|
|
32
|
-
// Handle MongoDB NumberInt format
|
|
33
|
-
if (value.$numberInt) {
|
|
34
|
-
return parseInt(value.$numberInt, 10);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Handle regular number
|
|
38
|
-
if (typeof value === 'number') {
|
|
39
|
-
return value;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Handle string number
|
|
43
|
-
if (typeof value === 'string') {
|
|
44
|
-
const parsed = parseInt(value, 10);
|
|
45
|
-
return isNaN(parsed) ? null : parsed;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Count guests arriving at exact time
|
|
53
|
-
* @param {Array} reservations - Reservation list
|
|
54
|
-
* @param {string} date - Date (YYYY-MM-DD)
|
|
55
|
-
* @param {string} time - Time (HH:MM)
|
|
56
|
-
* @returns {number} - Guest count
|
|
57
|
-
*/
|
|
58
|
-
function countArrivalsAtTime(reservations, date, time) {
|
|
59
|
-
return reservations
|
|
60
|
-
.filter(r => r.date === date && r.time === time)
|
|
61
|
-
.reduce((sum, r) => sum + (parseInt(r.guests, 10) || 0), 0);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Filter timeblocks based on max arrivals settings
|
|
66
|
-
* @param {Object} restaurantData - Restaurant data
|
|
67
|
-
* @param {string} date - Date string
|
|
68
|
-
* @param {Object} timeblocks - Available timeblocks
|
|
69
|
-
* @param {Array} reservations - Existing reservations
|
|
70
|
-
* @param {number} guests - New reservation guest count
|
|
71
|
-
* @returns {Object} - Filtered timeblocks
|
|
72
|
-
*/
|
|
73
|
-
function filterTimeblocksByMaxArrivals(restaurantData, date, timeblocks, reservations, guests) {
|
|
74
|
-
const filteredBlocks = {};
|
|
75
|
-
|
|
76
|
-
for (const [time, timeData] of Object.entries(timeblocks)) {
|
|
77
|
-
// Get meal type for this time
|
|
78
|
-
const mealType = getMealType(time);
|
|
79
|
-
if (!mealType) {
|
|
80
|
-
// Keep the timeblock if we can't determine its meal type
|
|
81
|
-
filteredBlocks[time] = timeData;
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Get max arrivals config for this meal type
|
|
86
|
-
const maxArrivalsConfig = restaurantData[`max-arrivals-${mealType}`];
|
|
87
|
-
if (!maxArrivalsConfig) {
|
|
88
|
-
// Keep the timeblock if no max arrivals config for this meal type
|
|
89
|
-
filteredBlocks[time] = timeData;
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Get max arrivals value for this specific time
|
|
94
|
-
const maxArrivals = extractNumber(maxArrivalsConfig[time]);
|
|
95
|
-
if (maxArrivals === null) {
|
|
96
|
-
// Keep the timeblock if no specific max arrivals for this time
|
|
97
|
-
filteredBlocks[time] = timeData;
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Count current arrivals at this exact time
|
|
102
|
-
const currentArrivals = countArrivalsAtTime(reservations, date, time);
|
|
103
|
-
|
|
104
|
-
// Only include timeblock if adding these guests doesn't exceed max arrivals
|
|
105
|
-
if (currentArrivals + guests <= maxArrivals) {
|
|
106
|
-
filteredBlocks[time] = timeData;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return filteredBlocks;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
module.exports = {
|
|
114
|
-
filterTimeblocksByMaxArrivals
|
|
1
|
+
// file: /src/Pages/NewReservation/StepOne/algorithm/maxArrivalsFilter.js
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Simple max arrivals filter for time slots
|
|
5
|
+
*
|
|
6
|
+
* Only considers exact arrivals at each time slot without factoring duration
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get meal type based on time
|
|
11
|
+
* @param {string} time - Time string (HH:MM)
|
|
12
|
+
* @returns {string|null} - Meal type or null
|
|
13
|
+
*/
|
|
14
|
+
function getMealType(time) {
|
|
15
|
+
const hour = parseInt(time.split(':')[0], 10);
|
|
16
|
+
|
|
17
|
+
if (hour >= 4 && hour < 11) return 'breakfast';
|
|
18
|
+
if (hour >= 11 && hour < 16) return 'lunch';
|
|
19
|
+
if (hour >= 16 && hour < 23) return 'dinner';
|
|
20
|
+
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Extract number value from various data formats
|
|
26
|
+
* @param {*} value - Value from data object
|
|
27
|
+
* @returns {number|null} - Number or null
|
|
28
|
+
*/
|
|
29
|
+
function extractNumber(value) {
|
|
30
|
+
if (!value) return null;
|
|
31
|
+
|
|
32
|
+
// Handle MongoDB NumberInt format
|
|
33
|
+
if (value.$numberInt) {
|
|
34
|
+
return parseInt(value.$numberInt, 10);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Handle regular number
|
|
38
|
+
if (typeof value === 'number') {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Handle string number
|
|
43
|
+
if (typeof value === 'string') {
|
|
44
|
+
const parsed = parseInt(value, 10);
|
|
45
|
+
return isNaN(parsed) ? null : parsed;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Count guests arriving at exact time
|
|
53
|
+
* @param {Array} reservations - Reservation list
|
|
54
|
+
* @param {string} date - Date (YYYY-MM-DD)
|
|
55
|
+
* @param {string} time - Time (HH:MM)
|
|
56
|
+
* @returns {number} - Guest count
|
|
57
|
+
*/
|
|
58
|
+
function countArrivalsAtTime(reservations, date, time) {
|
|
59
|
+
return reservations
|
|
60
|
+
.filter(r => r.date === date && r.time === time)
|
|
61
|
+
.reduce((sum, r) => sum + (parseInt(r.guests, 10) || 0), 0);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Filter timeblocks based on max arrivals settings
|
|
66
|
+
* @param {Object} restaurantData - Restaurant data
|
|
67
|
+
* @param {string} date - Date string
|
|
68
|
+
* @param {Object} timeblocks - Available timeblocks
|
|
69
|
+
* @param {Array} reservations - Existing reservations
|
|
70
|
+
* @param {number} guests - New reservation guest count
|
|
71
|
+
* @returns {Object} - Filtered timeblocks
|
|
72
|
+
*/
|
|
73
|
+
function filterTimeblocksByMaxArrivals(restaurantData, date, timeblocks, reservations, guests) {
|
|
74
|
+
const filteredBlocks = {};
|
|
75
|
+
|
|
76
|
+
for (const [time, timeData] of Object.entries(timeblocks)) {
|
|
77
|
+
// Get meal type for this time
|
|
78
|
+
const mealType = getMealType(time);
|
|
79
|
+
if (!mealType) {
|
|
80
|
+
// Keep the timeblock if we can't determine its meal type
|
|
81
|
+
filteredBlocks[time] = timeData;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Get max arrivals config for this meal type
|
|
86
|
+
const maxArrivalsConfig = restaurantData[`max-arrivals-${mealType}`];
|
|
87
|
+
if (!maxArrivalsConfig) {
|
|
88
|
+
// Keep the timeblock if no max arrivals config for this meal type
|
|
89
|
+
filteredBlocks[time] = timeData;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Get max arrivals value for this specific time
|
|
94
|
+
const maxArrivals = extractNumber(maxArrivalsConfig[time]);
|
|
95
|
+
if (maxArrivals === null) {
|
|
96
|
+
// Keep the timeblock if no specific max arrivals for this time
|
|
97
|
+
filteredBlocks[time] = timeData;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Count current arrivals at this exact time
|
|
102
|
+
const currentArrivals = countArrivalsAtTime(reservations, date, time);
|
|
103
|
+
|
|
104
|
+
// Only include timeblock if adding these guests doesn't exceed max arrivals
|
|
105
|
+
if (currentArrivals + guests <= maxArrivals) {
|
|
106
|
+
filteredBlocks[time] = timeData;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return filteredBlocks;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
module.exports = {
|
|
114
|
+
filterTimeblocksByMaxArrivals
|
|
115
115
|
};
|