@happychef/algorithm 1.2.11 → 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.
Files changed (57) hide show
  1. package/.github/workflows/ci-cd.yml +234 -234
  2. package/BRANCH_PROTECTION_SETUP.md +167 -167
  3. package/CHANGELOG.md +8 -8
  4. package/README.md +144 -144
  5. package/RESERVERINGEN_GIDS.md +986 -986
  6. package/__tests__/filters.test.js +276 -276
  7. package/__tests__/isDateAvailable.test.js +175 -175
  8. package/__tests__/isTimeAvailable.test.js +168 -168
  9. package/__tests__/restaurantData.test.js +422 -422
  10. package/__tests__/tableHelpers.test.js +247 -247
  11. package/assignTables.js +424 -424
  12. package/changes/2025/December/PR2___change.md +14 -14
  13. package/changes/2025/December/PR3_add__change.md +20 -20
  14. package/changes/2025/December/PR4___.md +15 -15
  15. package/changes/2025/December/PR5___.md +15 -15
  16. package/changes/2025/December/PR6__del_.md +17 -17
  17. package/changes/2025/December/PR7_add__change.md +21 -21
  18. package/changes/2026/January/PR8_add__change.md +39 -0
  19. package/changes/2026/January/PR9_add__change.md +20 -0
  20. package/filters/maxArrivalsFilter.js +114 -114
  21. package/filters/maxGroupsFilter.js +221 -221
  22. package/filters/timeFilter.js +89 -89
  23. package/getAvailableTimeblocks.js +158 -158
  24. package/grouping.js +162 -162
  25. package/index.js +42 -42
  26. package/isDateAvailable.js +80 -80
  27. package/isDateAvailableWithTableCheck.js +171 -171
  28. package/isTimeAvailable.js +25 -25
  29. package/jest.config.js +23 -23
  30. package/package.json +27 -27
  31. package/processing/dailyGuestCounts.js +73 -73
  32. package/processing/mealTypeCount.js +133 -133
  33. package/processing/timeblocksAvailable.js +167 -167
  34. package/reservation_data/counter.js +64 -64
  35. package/restaurant_data/exceptions.js +149 -149
  36. package/restaurant_data/openinghours.js +123 -123
  37. package/simulateTableAssignment.js +709 -699
  38. package/tableHelpers.js +178 -178
  39. package/tables/time/parseTime.js +19 -19
  40. package/tables/time/shifts.js +7 -7
  41. package/tables/utils/calculateDistance.js +13 -13
  42. package/tables/utils/isTableFreeForAllSlots.js +14 -14
  43. package/tables/utils/isTemporaryTableValid.js +39 -39
  44. package/test/test_counter.js +194 -194
  45. package/test/test_dailyCount.js +81 -81
  46. package/test/test_datesAvailable.js +106 -106
  47. package/test/test_exceptions.js +172 -172
  48. package/test/test_isDateAvailable.js +330 -330
  49. package/test/test_mealTypeCount.js +54 -54
  50. package/test/test_timesAvailable.js +88 -88
  51. package/test-detailed-filter.js +100 -100
  52. package/test-lunch-debug.js +110 -110
  53. package/test-max-arrivals-filter.js +79 -79
  54. package/test-meal-stop-fix.js +147 -147
  55. package/test-meal-stop-simple.js +93 -93
  56. package/test-timezone-debug.js +47 -47
  57. package/test.js +336 -336
package/tableHelpers.js CHANGED
@@ -1,178 +1,178 @@
1
- // file: client side ./algorithm/tableHelpers.js
2
-
3
- // --- Time and Shift Helpers ---
4
-
5
- /**
6
- * Parses a time string ("HH:MM") into minutes since midnight.
7
- * Returns NaN if the format is invalid.
8
- */
9
- function parseTime(timeStr) {
10
- if (!timeStr || typeof timeStr !== 'string') return NaN;
11
- const parts = timeStr.split(':');
12
- if (parts.length !== 2) return NaN;
13
- const hours = parseInt(parts[0], 10);
14
- const minutes = parseInt(parts[1], 10);
15
- if (isNaN(hours) || isNaN(minutes) || hours < 0 || hours > 23 || minutes < 0 || minutes > 59) {
16
- return NaN;
17
- }
18
- return hours * 60 + minutes;
19
- }
20
-
21
- const shifts = {
22
- breakfast: { start: '07:00', end: '11:00' },
23
- lunch: { start: '11:00', end: '16:00' },
24
- dinner: { start: '16:00', end: '23:00' }, // Adjust end time if needed
25
- };
26
-
27
- /**
28
- * Determines the meal type ('breakfast', 'lunch', 'dinner') for a given time string ("HH:MM").
29
- * Returns null if the time doesn't fall into a defined shift.
30
- */
31
- function getMealTypeByTime(timeStr) {
32
- const time = parseTime(timeStr);
33
- if (isNaN(time)) return null;
34
-
35
- for (const [mealType, shift] of Object.entries(shifts)) {
36
- const start = parseTime(shift.start);
37
- const end = parseTime(shift.end);
38
- // Handle potential errors from parseTime if shift definitions are invalid
39
- if (isNaN(start) || isNaN(end)) continue;
40
-
41
- // Check if time falls within the shift range [start, end)
42
- if (time >= start && time < end) {
43
- return mealType;
44
- }
45
- }
46
- return null; // Return null if no matching shift is found
47
- }
48
-
49
-
50
- // --- Table Fetching ---
51
-
52
- /**
53
- * Extracts and processes table data from the restaurantData object.
54
- * Includes temporary table properties and sorts tables.
55
- * @param {Object} restaurantData - The main restaurant data object.
56
- * @returns {Array} An array of processed table objects.
57
- */
58
- function getAllTables(restaurantData) {
59
- let allTables = [];
60
- if (restaurantData?.floors && Array.isArray(restaurantData.floors)) {
61
- restaurantData.floors.forEach(floor => {
62
- if (floor?.tables && Array.isArray(floor.tables)) {
63
- floor.tables.forEach(tbl => {
64
- // Ensure table number, capacities, priority exist before parsing
65
- const tableNumberRaw = tbl.tableNumber?.$numberInt ?? tbl.tableNumber;
66
- const minCapacityRaw = tbl.minCapacity?.$numberInt ?? tbl.minCapacity;
67
- const maxCapacityRaw = tbl.maxCapacity?.$numberInt ?? tbl.maxCapacity;
68
- const priorityRaw = tbl.priority?.$numberInt ?? tbl.priority;
69
- const xRaw = tbl.x?.$numberInt ?? tbl.x;
70
- const yRaw = tbl.y?.$numberInt ?? tbl.y;
71
-
72
- if (tbl.objectType === "Tafel" &&
73
- tableNumberRaw !== undefined &&
74
- minCapacityRaw !== undefined &&
75
- maxCapacityRaw !== undefined &&
76
- priorityRaw !== undefined &&
77
- xRaw !== undefined &&
78
- yRaw !== undefined)
79
- {
80
- allTables.push({
81
- tableId: tbl.id,
82
- tableNumber: parseInt(tableNumberRaw, 10),
83
- minCapacity: parseInt(minCapacityRaw, 10),
84
- maxCapacity: parseInt(maxCapacityRaw, 10),
85
- priority: parseInt(priorityRaw, 10),
86
- x: parseInt(xRaw, 10),
87
- y: parseInt(yRaw, 10),
88
- isTemporary: tbl.isTemporary === true, // Ensure boolean
89
- startDate: tbl.startDate || null, // Expects 'YYYY-MM-DD'
90
- endDate: tbl.endDate || null, // Expects 'YYYY-MM-DD'
91
- application: tbl.application || null // Expects 'breakfast', 'lunch', or 'dinner'
92
- });
93
- } else if (tbl.objectType === "Tafel") {
94
- console.warn(`Skipping table due to missing essential properties: ${JSON.stringify(tbl)}`);
95
- }
96
- });
97
- }
98
- });
99
- } else {
100
- console.warn("Restaurant data is missing 'floors' array.");
101
- }
102
-
103
- // Sort tables
104
- allTables.sort((a, b) => {
105
- if (a.maxCapacity !== b.maxCapacity) {
106
- return a.maxCapacity - b.maxCapacity;
107
- }
108
- if (a.priority !== b.priority) {
109
- // Assuming lower priority number means higher priority
110
- return a.priority - b.priority;
111
- }
112
- return a.minCapacity - b.minCapacity;
113
- });
114
-
115
- // Filter out tables where parsing failed (resulted in NaN)
116
- allTables = allTables.filter(t =>
117
- !isNaN(t.tableNumber) &&
118
- !isNaN(t.minCapacity) &&
119
- !isNaN(t.maxCapacity) &&
120
- !isNaN(t.priority) &&
121
- !isNaN(t.x) &&
122
- !isNaN(t.y)
123
- );
124
-
125
- return allTables;
126
- }
127
-
128
-
129
- // --- Temporary Table Validation ---
130
-
131
- /**
132
- * Checks if a temporary table is valid for a specific reservation date and time.
133
- * @param {Object} table - The table object (must include isTemporary, startDate, endDate, application).
134
- * @param {string} reservationDateStr - The date of the reservation ("YYYY-MM-DD").
135
- * @param {string} reservationTimeStr - The time of the reservation ("HH:MM").
136
- * @returns {boolean} True if the table is valid, false otherwise.
137
- */
138
- function isTemporaryTableValid(table, reservationDateStr, reservationTimeStr) {
139
- if (!table.isTemporary) {
140
- return true; // Not temporary, always valid (subject to other checks like availability)
141
- }
142
-
143
- // Check date range
144
- if (!table.startDate || !table.endDate) {
145
- console.log(`Temporary Table ${table.tableNumber} skipped: Missing start/end date.`);
146
- return false; // Invalid temporary table definition
147
- }
148
- // Basic date string comparison (YYYY-MM-DD format)
149
- if (reservationDateStr < table.startDate || reservationDateStr > table.endDate) {
150
- // console.log(`Temporary Table ${table.tableNumber} skipped: Date ${reservationDateStr} outside range ${table.startDate}-${table.endDate}.`); // Optional verbose logging
151
- return false;
152
- }
153
-
154
- // Check application (meal type/shift)
155
- const reservationMealType = getMealTypeByTime(reservationTimeStr);
156
- if (!reservationMealType) {
157
- console.log(`Temporary Table ${table.tableNumber} skipped: Could not determine meal type for time ${reservationTimeStr}.`);
158
- return false; // Cannot determine meal type for the reservation
159
- }
160
- if (table.application !== reservationMealType) {
161
- // console.log(`Temporary Table ${table.tableNumber} skipped: Application '${table.application}' does not match reservation meal type '${reservationMealType}'.`); // Optional verbose logging
162
- return false;
163
- }
164
-
165
- // console.log(`Temporary Table ${table.tableNumber} is valid for ${reservationDateStr} at ${reservationTimeStr} (${reservationMealType}).`); // Optional verbose logging
166
- return true;
167
- }
168
-
169
-
170
- // --- Exports ---
171
- // Use CommonJS exports (adjust if using ES6 modules)
172
- module.exports = {
173
- shifts,
174
- parseTime,
175
- getMealTypeByTime,
176
- getAllTables,
177
- isTemporaryTableValid
178
- };
1
+ // file: client side ./algorithm/tableHelpers.js
2
+
3
+ // --- Time and Shift Helpers ---
4
+
5
+ /**
6
+ * Parses a time string ("HH:MM") into minutes since midnight.
7
+ * Returns NaN if the format is invalid.
8
+ */
9
+ function parseTime(timeStr) {
10
+ if (!timeStr || typeof timeStr !== 'string') return NaN;
11
+ const parts = timeStr.split(':');
12
+ if (parts.length !== 2) return NaN;
13
+ const hours = parseInt(parts[0], 10);
14
+ const minutes = parseInt(parts[1], 10);
15
+ if (isNaN(hours) || isNaN(minutes) || hours < 0 || hours > 23 || minutes < 0 || minutes > 59) {
16
+ return NaN;
17
+ }
18
+ return hours * 60 + minutes;
19
+ }
20
+
21
+ const shifts = {
22
+ breakfast: { start: '07:00', end: '11:00' },
23
+ lunch: { start: '11:00', end: '16:00' },
24
+ dinner: { start: '16:00', end: '23:00' }, // Adjust end time if needed
25
+ };
26
+
27
+ /**
28
+ * Determines the meal type ('breakfast', 'lunch', 'dinner') for a given time string ("HH:MM").
29
+ * Returns null if the time doesn't fall into a defined shift.
30
+ */
31
+ function getMealTypeByTime(timeStr) {
32
+ const time = parseTime(timeStr);
33
+ if (isNaN(time)) return null;
34
+
35
+ for (const [mealType, shift] of Object.entries(shifts)) {
36
+ const start = parseTime(shift.start);
37
+ const end = parseTime(shift.end);
38
+ // Handle potential errors from parseTime if shift definitions are invalid
39
+ if (isNaN(start) || isNaN(end)) continue;
40
+
41
+ // Check if time falls within the shift range [start, end)
42
+ if (time >= start && time < end) {
43
+ return mealType;
44
+ }
45
+ }
46
+ return null; // Return null if no matching shift is found
47
+ }
48
+
49
+
50
+ // --- Table Fetching ---
51
+
52
+ /**
53
+ * Extracts and processes table data from the restaurantData object.
54
+ * Includes temporary table properties and sorts tables.
55
+ * @param {Object} restaurantData - The main restaurant data object.
56
+ * @returns {Array} An array of processed table objects.
57
+ */
58
+ function getAllTables(restaurantData) {
59
+ let allTables = [];
60
+ if (restaurantData?.floors && Array.isArray(restaurantData.floors)) {
61
+ restaurantData.floors.forEach(floor => {
62
+ if (floor?.tables && Array.isArray(floor.tables)) {
63
+ floor.tables.forEach(tbl => {
64
+ // Ensure table number, capacities, priority exist before parsing
65
+ const tableNumberRaw = tbl.tableNumber?.$numberInt ?? tbl.tableNumber;
66
+ const minCapacityRaw = tbl.minCapacity?.$numberInt ?? tbl.minCapacity;
67
+ const maxCapacityRaw = tbl.maxCapacity?.$numberInt ?? tbl.maxCapacity;
68
+ const priorityRaw = tbl.priority?.$numberInt ?? tbl.priority;
69
+ const xRaw = tbl.x?.$numberInt ?? tbl.x;
70
+ const yRaw = tbl.y?.$numberInt ?? tbl.y;
71
+
72
+ if (tbl.objectType === "Tafel" &&
73
+ tableNumberRaw !== undefined &&
74
+ minCapacityRaw !== undefined &&
75
+ maxCapacityRaw !== undefined &&
76
+ priorityRaw !== undefined &&
77
+ xRaw !== undefined &&
78
+ yRaw !== undefined)
79
+ {
80
+ allTables.push({
81
+ tableId: tbl.id,
82
+ tableNumber: parseInt(tableNumberRaw, 10),
83
+ minCapacity: parseInt(minCapacityRaw, 10),
84
+ maxCapacity: parseInt(maxCapacityRaw, 10),
85
+ priority: parseInt(priorityRaw, 10),
86
+ x: parseInt(xRaw, 10),
87
+ y: parseInt(yRaw, 10),
88
+ isTemporary: tbl.isTemporary === true, // Ensure boolean
89
+ startDate: tbl.startDate || null, // Expects 'YYYY-MM-DD'
90
+ endDate: tbl.endDate || null, // Expects 'YYYY-MM-DD'
91
+ application: tbl.application || null // Expects 'breakfast', 'lunch', or 'dinner'
92
+ });
93
+ } else if (tbl.objectType === "Tafel") {
94
+ console.warn(`Skipping table due to missing essential properties: ${JSON.stringify(tbl)}`);
95
+ }
96
+ });
97
+ }
98
+ });
99
+ } else {
100
+ console.warn("Restaurant data is missing 'floors' array.");
101
+ }
102
+
103
+ // Sort tables
104
+ allTables.sort((a, b) => {
105
+ if (a.maxCapacity !== b.maxCapacity) {
106
+ return a.maxCapacity - b.maxCapacity;
107
+ }
108
+ if (a.priority !== b.priority) {
109
+ // Assuming lower priority number means higher priority
110
+ return a.priority - b.priority;
111
+ }
112
+ return a.minCapacity - b.minCapacity;
113
+ });
114
+
115
+ // Filter out tables where parsing failed (resulted in NaN)
116
+ allTables = allTables.filter(t =>
117
+ !isNaN(t.tableNumber) &&
118
+ !isNaN(t.minCapacity) &&
119
+ !isNaN(t.maxCapacity) &&
120
+ !isNaN(t.priority) &&
121
+ !isNaN(t.x) &&
122
+ !isNaN(t.y)
123
+ );
124
+
125
+ return allTables;
126
+ }
127
+
128
+
129
+ // --- Temporary Table Validation ---
130
+
131
+ /**
132
+ * Checks if a temporary table is valid for a specific reservation date and time.
133
+ * @param {Object} table - The table object (must include isTemporary, startDate, endDate, application).
134
+ * @param {string} reservationDateStr - The date of the reservation ("YYYY-MM-DD").
135
+ * @param {string} reservationTimeStr - The time of the reservation ("HH:MM").
136
+ * @returns {boolean} True if the table is valid, false otherwise.
137
+ */
138
+ function isTemporaryTableValid(table, reservationDateStr, reservationTimeStr) {
139
+ if (!table.isTemporary) {
140
+ return true; // Not temporary, always valid (subject to other checks like availability)
141
+ }
142
+
143
+ // Check date range
144
+ if (!table.startDate || !table.endDate) {
145
+ console.log(`Temporary Table ${table.tableNumber} skipped: Missing start/end date.`);
146
+ return false; // Invalid temporary table definition
147
+ }
148
+ // Basic date string comparison (YYYY-MM-DD format)
149
+ if (reservationDateStr < table.startDate || reservationDateStr > table.endDate) {
150
+ // console.log(`Temporary Table ${table.tableNumber} skipped: Date ${reservationDateStr} outside range ${table.startDate}-${table.endDate}.`); // Optional verbose logging
151
+ return false;
152
+ }
153
+
154
+ // Check application (meal type/shift)
155
+ const reservationMealType = getMealTypeByTime(reservationTimeStr);
156
+ if (!reservationMealType) {
157
+ console.log(`Temporary Table ${table.tableNumber} skipped: Could not determine meal type for time ${reservationTimeStr}.`);
158
+ return false; // Cannot determine meal type for the reservation
159
+ }
160
+ if (table.application !== reservationMealType) {
161
+ // console.log(`Temporary Table ${table.tableNumber} skipped: Application '${table.application}' does not match reservation meal type '${reservationMealType}'.`); // Optional verbose logging
162
+ return false;
163
+ }
164
+
165
+ // console.log(`Temporary Table ${table.tableNumber} is valid for ${reservationDateStr} at ${reservationTimeStr} (${reservationMealType}).`); // Optional verbose logging
166
+ return true;
167
+ }
168
+
169
+
170
+ // --- Exports ---
171
+ // Use CommonJS exports (adjust if using ES6 modules)
172
+ module.exports = {
173
+ shifts,
174
+ parseTime,
175
+ getMealTypeByTime,
176
+ getAllTables,
177
+ isTemporaryTableValid
178
+ };
@@ -1,19 +1,19 @@
1
- // --- Time and Shift Helpers ---
2
-
3
- /**
4
- * Parses a time string ("HH:MM") into minutes since midnight.
5
- * Returns NaN if the format is invalid.
6
- */
7
- function parseTime(timeStr) {
8
- if (!timeStr || typeof timeStr !== 'string') return NaN;
9
- const parts = timeStr.split(':');
10
- if (parts.length !== 2) return NaN;
11
- const hours = parseInt(parts[0], 10);
12
- const minutes = parseInt(parts[1], 10);
13
- if (isNaN(hours) || isNaN(minutes) || hours < 0 || hours > 23 || minutes < 0 || minutes > 59) {
14
- return NaN;
15
- }
16
- return hours * 60 + minutes;
17
- }
18
-
19
- module.exports = parseTime;
1
+ // --- Time and Shift Helpers ---
2
+
3
+ /**
4
+ * Parses a time string ("HH:MM") into minutes since midnight.
5
+ * Returns NaN if the format is invalid.
6
+ */
7
+ function parseTime(timeStr) {
8
+ if (!timeStr || typeof timeStr !== 'string') return NaN;
9
+ const parts = timeStr.split(':');
10
+ if (parts.length !== 2) return NaN;
11
+ const hours = parseInt(parts[0], 10);
12
+ const minutes = parseInt(parts[1], 10);
13
+ if (isNaN(hours) || isNaN(minutes) || hours < 0 || hours > 23 || minutes < 0 || minutes > 59) {
14
+ return NaN;
15
+ }
16
+ return hours * 60 + minutes;
17
+ }
18
+
19
+ module.exports = parseTime;
@@ -1,7 +1,7 @@
1
- const shifts = {
2
- breakfast: { start: '07:00', end: '11:00' },
3
- lunch: { start: '11:00', end: '16:00' },
4
- dinner: { start: '16:00', end: '23:00' }, // Adjust end time if needed
5
- };
6
-
7
- module.exports = { shifts };
1
+ const shifts = {
2
+ breakfast: { start: '07:00', end: '11:00' },
3
+ lunch: { start: '11:00', end: '16:00' },
4
+ dinner: { start: '16:00', end: '23:00' }, // Adjust end time if needed
5
+ };
6
+
7
+ module.exports = { shifts };
@@ -1,13 +1,13 @@
1
- /**
2
- * Calculates Euclidean distance between two tables (assuming x, y properties).
3
- */
4
- function calculateDistance(tableA, tableB) {
5
- if (tableA?.x === undefined || tableA?.y === undefined || tableB?.x === undefined || tableB?.y === undefined) {
6
- return Infinity; // Cannot calculate distance if coordinates are missing
7
- }
8
- const dx = tableA.x - tableB.x;
9
- const dy = tableA.y - tableB.y;
10
- return Math.sqrt(dx * dx + dy * dy);
11
- }
12
-
13
- module.exports = calculateDistance;
1
+ /**
2
+ * Calculates Euclidean distance between two tables (assuming x, y properties).
3
+ */
4
+ function calculateDistance(tableA, tableB) {
5
+ if (tableA?.x === undefined || tableA?.y === undefined || tableB?.x === undefined || tableB?.y === undefined) {
6
+ return Infinity; // Cannot calculate distance if coordinates are missing
7
+ }
8
+ const dx = tableA.x - tableB.x;
9
+ const dy = tableA.y - tableB.y;
10
+ return Math.sqrt(dx * dx + dy * dy);
11
+ }
12
+
13
+ module.exports = calculateDistance;
@@ -1,14 +1,14 @@
1
- /**
2
- * Checks if the given tableNumber is free for all requiredSlots based on the occupied map.
3
- */
4
- function isTableFreeForAllSlots(tableNumber, requiredSlots, tableOccupiedSlots) {
5
- const occupiedSlots = tableOccupiedSlots[tableNumber] || new Set();
6
- for (const slot of requiredSlots) {
7
- if (occupiedSlots.has(slot)) {
8
- return false;
9
- }
10
- }
11
- return true;
12
- }
13
-
14
- module.exports = isTableFreeForAllSlots;
1
+ /**
2
+ * Checks if the given tableNumber is free for all requiredSlots based on the occupied map.
3
+ */
4
+ function isTableFreeForAllSlots(tableNumber, requiredSlots, tableOccupiedSlots) {
5
+ const occupiedSlots = tableOccupiedSlots[tableNumber] || new Set();
6
+ for (const slot of requiredSlots) {
7
+ if (occupiedSlots.has(slot)) {
8
+ return false;
9
+ }
10
+ }
11
+ return true;
12
+ }
13
+
14
+ module.exports = isTableFreeForAllSlots;
@@ -1,39 +1,39 @@
1
- const getMealTypeByTime = require('../time/getMealTypeByTime');
2
-
3
- /**
4
- * Checks if a temporary table is valid for a specific reservation date and time.
5
- * @param {Object} table - The table object (must include isTemporary, startDate, endDate, application).
6
- * @param {string} reservationDateStr - The date of the reservation ("YYYY-MM-DD").
7
- * @param {string} reservationTimeStr - The time of the reservation ("HH:MM").
8
- * @returns {boolean} True if the table is valid, false otherwise.
9
- */
10
- function isTemporaryTableValid(table, reservationDateStr, reservationTimeStr) {
11
- if (!table.isTemporary) {
12
- return true; // Not temporary, always valid (subject to other checks like availability)
13
- }
14
-
15
- // Check date range
16
- if (!table.startDate || !table.endDate) {
17
- return false; // Invalid temporary table definition
18
- }
19
- // Basic date string comparison (YYYY-MM-DD format)
20
- if (reservationDateStr < table.startDate || reservationDateStr > table.endDate) {
21
- // console.log(`Temporary Table ${table.tableNumber} skipped: Date ${reservationDateStr} outside range ${table.startDate}-${table.endDate}.`); // Optional verbose logging
22
- return false;
23
- }
24
-
25
- // Check application (meal type/shift)
26
- const reservationMealType = getMealTypeByTime(reservationTimeStr);
27
- if (!reservationMealType) {
28
- return false; // Cannot determine meal type for the reservation
29
- }
30
- if (table.application !== reservationMealType) {
31
- // console.log(`Temporary Table ${table.tableNumber} skipped: Application '${table.application}' does not match reservation meal type '${reservationMealType}'.`); // Optional verbose logging
32
- return false;
33
- }
34
-
35
- // console.log(`Temporary Table ${table.tableNumber} is valid for ${reservationDateStr} at ${reservationTimeStr} (${reservationMealType}).`); // Optional verbose logging
36
- return true;
37
- }
38
-
39
- module.exports = isTemporaryTableValid;
1
+ const getMealTypeByTime = require('../time/getMealTypeByTime');
2
+
3
+ /**
4
+ * Checks if a temporary table is valid for a specific reservation date and time.
5
+ * @param {Object} table - The table object (must include isTemporary, startDate, endDate, application).
6
+ * @param {string} reservationDateStr - The date of the reservation ("YYYY-MM-DD").
7
+ * @param {string} reservationTimeStr - The time of the reservation ("HH:MM").
8
+ * @returns {boolean} True if the table is valid, false otherwise.
9
+ */
10
+ function isTemporaryTableValid(table, reservationDateStr, reservationTimeStr) {
11
+ if (!table.isTemporary) {
12
+ return true; // Not temporary, always valid (subject to other checks like availability)
13
+ }
14
+
15
+ // Check date range
16
+ if (!table.startDate || !table.endDate) {
17
+ return false; // Invalid temporary table definition
18
+ }
19
+ // Basic date string comparison (YYYY-MM-DD format)
20
+ if (reservationDateStr < table.startDate || reservationDateStr > table.endDate) {
21
+ // console.log(`Temporary Table ${table.tableNumber} skipped: Date ${reservationDateStr} outside range ${table.startDate}-${table.endDate}.`); // Optional verbose logging
22
+ return false;
23
+ }
24
+
25
+ // Check application (meal type/shift)
26
+ const reservationMealType = getMealTypeByTime(reservationTimeStr);
27
+ if (!reservationMealType) {
28
+ return false; // Cannot determine meal type for the reservation
29
+ }
30
+ if (table.application !== reservationMealType) {
31
+ // console.log(`Temporary Table ${table.tableNumber} skipped: Application '${table.application}' does not match reservation meal type '${reservationMealType}'.`); // Optional verbose logging
32
+ return false;
33
+ }
34
+
35
+ // console.log(`Temporary Table ${table.tableNumber} is valid for ${reservationDateStr} at ${reservationTimeStr} (${reservationMealType}).`); // Optional verbose logging
36
+ return true;
37
+ }
38
+
39
+ module.exports = isTemporaryTableValid;