@happychef/algorithm 1.3.0 → 1.3.5

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 (56) hide show
  1. package/.github/workflows/ci-cd.yml +80 -80
  2. package/CHANGELOG.md +8 -8
  3. package/RESERVERINGEN_GIDS.md +986 -986
  4. package/assignTables.js +444 -444
  5. package/bundle_entry.js +100 -0
  6. package/changes/2025/December/PR2___change.md +14 -14
  7. package/changes/2025/December/PR3_add__change.md +20 -20
  8. package/changes/2025/December/PR4___.md +15 -15
  9. package/changes/2025/December/PR5___.md +15 -15
  10. package/changes/2025/December/PR6__del_.md +17 -17
  11. package/changes/2025/December/PR7_add__change.md +21 -21
  12. package/changes/2026/February/PR15_add__change.md +21 -21
  13. package/changes/2026/January/PR10_add__change.md +21 -21
  14. package/changes/2026/January/PR11_add__change.md +19 -19
  15. package/changes/2026/January/PR12_add__.md +21 -21
  16. package/changes/2026/January/PR13_add__change.md +20 -20
  17. package/changes/2026/January/PR14_add__change.md +19 -19
  18. package/changes/2026/January/PR8_add__change.md +38 -38
  19. package/changes/2026/January/PR9_add__change.md +19 -19
  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 +170 -158
  24. package/grouping.js +162 -162
  25. package/index.js +42 -43
  26. package/isDateAvailable.js +80 -80
  27. package/isDateAvailableWithTableCheck.js +172 -172
  28. package/isTimeAvailable.js +26 -26
  29. package/moment-timezone-shim.js +179 -0
  30. package/nul +0 -0
  31. package/package.json +27 -27
  32. package/processing/dailyGuestCounts.js +73 -73
  33. package/processing/mealTypeCount.js +133 -133
  34. package/processing/timeblocksAvailable.js +194 -182
  35. package/reservation_data/counter.js +74 -74
  36. package/restaurant_data/exceptions.js +150 -150
  37. package/restaurant_data/openinghours.js +166 -142
  38. package/simulateTableAssignment.js +727 -726
  39. package/tableHelpers.js +212 -209
  40. package/tables/time/parseTime.js +19 -19
  41. package/tables/time/shifts.js +7 -7
  42. package/tables/utils/calculateDistance.js +13 -13
  43. package/tables/utils/isTableFreeForAllSlots.js +14 -14
  44. package/tables/utils/isTemporaryTableValid.js +39 -39
  45. package/test/test_counter.js +194 -194
  46. package/test/test_dailyCount.js +81 -81
  47. package/test/test_datesAvailable.js +106 -106
  48. package/test/test_exceptions.js +172 -172
  49. package/test/test_isDateAvailable.js +330 -330
  50. package/test/test_mealTypeCount.js +54 -54
  51. package/test/test_timesAvailable.js +88 -88
  52. package/test-meal-stop-fix.js +147 -147
  53. package/test-meal-stop-simple.js +93 -93
  54. package/test.js +336 -336
  55. package/changes/2026/February/PR16_add_getDateClosingReasons.md +0 -31
  56. package/getDateClosingReasons.js +0 -193
package/tableHelpers.js CHANGED
@@ -1,209 +1,212 @@
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
- * Gets the floor ID linked to a seat place from seatAreaFloorLinks.
54
- * Mirrors the server-side getFloorIdForSeatPlace in assignTables.js.
55
- * @param {Object} restaurantData - The restaurant data object.
56
- * @param {string} seatPlace - The seat place identifier (zitplaats).
57
- * @returns {string|null} The floor ID or null if not found.
58
- */
59
- function getFloorIdForSeatPlace(restaurantData, seatPlace) {
60
- if (!seatPlace || !restaurantData) return null;
61
- const seatAreaFloorLinks = restaurantData["general-settings"]?.seatAreaFloorLinks;
62
- if (!seatAreaFloorLinks || typeof seatAreaFloorLinks !== 'object') return null;
63
- return seatAreaFloorLinks[seatPlace] || null;
64
- }
65
-
66
- /**
67
- * Extracts and processes table data from the restaurantData object.
68
- * Includes temporary table properties and sorts tables.
69
- * When selectedZitplaats is provided and has a linked floor via seatAreaFloorLinks,
70
- * only tables from that linked floor are returned (matching server-side behavior).
71
- * @param {Object} restaurantData - The main restaurant data object.
72
- * @param {string|null} selectedZitplaats - Optional seat place to filter by linked floor.
73
- * @returns {Array} An array of processed table objects.
74
- */
75
- function getAllTables(restaurantData, selectedZitplaats) {
76
- let allTables = [];
77
- if (restaurantData?.floors && Array.isArray(restaurantData.floors)) {
78
- // If a zitplaats is specified and has a floor link, only use that floor
79
- let floorsToUse = restaurantData.floors;
80
- if (selectedZitplaats) {
81
- const linkedFloorId = getFloorIdForSeatPlace(restaurantData, selectedZitplaats);
82
- if (linkedFloorId) {
83
- const linkedFloor = restaurantData.floors.find(f => f.id === linkedFloorId);
84
- if (linkedFloor) {
85
- floorsToUse = [linkedFloor];
86
- console.log(`[getAllTables] Floor link found: zitplaats '${selectedZitplaats}' -> floor '${linkedFloorId}'`);
87
- }
88
- }
89
- }
90
-
91
- floorsToUse.forEach(floor => {
92
- if (floor?.tables && Array.isArray(floor.tables)) {
93
- floor.tables.forEach(tbl => {
94
- // Ensure table number, capacities, priority exist before parsing
95
- const tableNumberRaw = tbl.tableNumber?.$numberInt ?? tbl.tableNumber;
96
- const minCapacityRaw = tbl.minCapacity?.$numberInt ?? tbl.minCapacity;
97
- const maxCapacityRaw = tbl.maxCapacity?.$numberInt ?? tbl.maxCapacity;
98
- const priorityRaw = tbl.priority?.$numberInt ?? tbl.priority;
99
- const xRaw = tbl.x?.$numberInt ?? tbl.x;
100
- const yRaw = tbl.y?.$numberInt ?? tbl.y;
101
-
102
- if (tbl.objectType === "Tafel" &&
103
- tableNumberRaw !== undefined &&
104
- minCapacityRaw !== undefined &&
105
- maxCapacityRaw !== undefined &&
106
- priorityRaw !== undefined &&
107
- xRaw !== undefined &&
108
- yRaw !== undefined)
109
- {
110
- allTables.push({
111
- tableId: tbl.id,
112
- tableNumber: parseInt(tableNumberRaw, 10),
113
- minCapacity: parseInt(minCapacityRaw, 10),
114
- maxCapacity: parseInt(maxCapacityRaw, 10),
115
- priority: parseInt(priorityRaw, 10),
116
- x: parseInt(xRaw, 10),
117
- y: parseInt(yRaw, 10),
118
- isTemporary: tbl.isTemporary === true, // Ensure boolean
119
- startDate: tbl.startDate || null, // Expects 'YYYY-MM-DD'
120
- endDate: tbl.endDate || null, // Expects 'YYYY-MM-DD'
121
- application: tbl.application || null // Expects 'breakfast', 'lunch', or 'dinner'
122
- });
123
- } else if (tbl.objectType === "Tafel") {
124
- console.warn(`Skipping table due to missing essential properties: ${JSON.stringify(tbl)}`);
125
- }
126
- });
127
- }
128
- });
129
- } else {
130
- console.warn("Restaurant data is missing 'floors' array.");
131
- }
132
-
133
- // Sort tables
134
- allTables.sort((a, b) => {
135
- if (a.maxCapacity !== b.maxCapacity) {
136
- return a.maxCapacity - b.maxCapacity;
137
- }
138
- if (a.priority !== b.priority) {
139
- // Assuming lower priority number means higher priority
140
- return a.priority - b.priority;
141
- }
142
- return a.minCapacity - b.minCapacity;
143
- });
144
-
145
- // Filter out tables where parsing failed (resulted in NaN)
146
- allTables = allTables.filter(t =>
147
- !isNaN(t.tableNumber) &&
148
- !isNaN(t.minCapacity) &&
149
- !isNaN(t.maxCapacity) &&
150
- !isNaN(t.priority) &&
151
- !isNaN(t.x) &&
152
- !isNaN(t.y)
153
- );
154
-
155
- return allTables;
156
- }
157
-
158
-
159
- // --- Temporary Table Validation ---
160
-
161
- /**
162
- * Checks if a temporary table is valid for a specific reservation date and time.
163
- * @param {Object} table - The table object (must include isTemporary, startDate, endDate, application).
164
- * @param {string} reservationDateStr - The date of the reservation ("YYYY-MM-DD").
165
- * @param {string} reservationTimeStr - The time of the reservation ("HH:MM").
166
- * @returns {boolean} True if the table is valid, false otherwise.
167
- */
168
- function isTemporaryTableValid(table, reservationDateStr, reservationTimeStr) {
169
- if (!table.isTemporary) {
170
- return true; // Not temporary, always valid (subject to other checks like availability)
171
- }
172
-
173
- // Check date range
174
- if (!table.startDate || !table.endDate) {
175
- console.log(`Temporary Table ${table.tableNumber} skipped: Missing start/end date.`);
176
- return false; // Invalid temporary table definition
177
- }
178
- // Basic date string comparison (YYYY-MM-DD format)
179
- if (reservationDateStr < table.startDate || reservationDateStr > table.endDate) {
180
- // console.log(`Temporary Table ${table.tableNumber} skipped: Date ${reservationDateStr} outside range ${table.startDate}-${table.endDate}.`); // Optional verbose logging
181
- return false;
182
- }
183
-
184
- // Check application (meal type/shift)
185
- const reservationMealType = getMealTypeByTime(reservationTimeStr);
186
- if (!reservationMealType) {
187
- console.log(`Temporary Table ${table.tableNumber} skipped: Could not determine meal type for time ${reservationTimeStr}.`);
188
- return false; // Cannot determine meal type for the reservation
189
- }
190
- if (table.application !== reservationMealType) {
191
- // console.log(`Temporary Table ${table.tableNumber} skipped: Application '${table.application}' does not match reservation meal type '${reservationMealType}'.`); // Optional verbose logging
192
- return false;
193
- }
194
-
195
- // console.log(`Temporary Table ${table.tableNumber} is valid for ${reservationDateStr} at ${reservationTimeStr} (${reservationMealType}).`); // Optional verbose logging
196
- return true;
197
- }
198
-
199
-
200
- // --- Exports ---
201
- // Use CommonJS exports (adjust if using ES6 modules)
202
- module.exports = {
203
- shifts,
204
- parseTime,
205
- getMealTypeByTime,
206
- getAllTables,
207
- getFloorIdForSeatPlace,
208
- isTemporaryTableValid
209
- };
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 || 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
+ // Times at or past dinner end are considered dinner (cross-midnight support for bowling)
47
+ const dinnerEnd = parseTime(shifts.dinner.end);
48
+ if (!isNaN(dinnerEnd) && time >= dinnerEnd) return 'dinner';
49
+ return null;
50
+ }
51
+
52
+
53
+ // --- Table Fetching ---
54
+
55
+ /**
56
+ * Gets the floor ID linked to a seat place from seatAreaFloorLinks.
57
+ * Mirrors the server-side getFloorIdForSeatPlace in assignTables.js.
58
+ * @param {Object} restaurantData - The restaurant data object.
59
+ * @param {string} seatPlace - The seat place identifier (zitplaats).
60
+ * @returns {string|null} The floor ID or null if not found.
61
+ */
62
+ function getFloorIdForSeatPlace(restaurantData, seatPlace) {
63
+ if (!seatPlace || !restaurantData) return null;
64
+ const seatAreaFloorLinks = restaurantData["general-settings"]?.seatAreaFloorLinks;
65
+ if (!seatAreaFloorLinks || typeof seatAreaFloorLinks !== 'object') return null;
66
+ return seatAreaFloorLinks[seatPlace] || null;
67
+ }
68
+
69
+ /**
70
+ * Extracts and processes table data from the restaurantData object.
71
+ * Includes temporary table properties and sorts tables.
72
+ * When selectedZitplaats is provided and has a linked floor via seatAreaFloorLinks,
73
+ * only tables from that linked floor are returned (matching server-side behavior).
74
+ * @param {Object} restaurantData - The main restaurant data object.
75
+ * @param {string|null} selectedZitplaats - Optional seat place to filter by linked floor.
76
+ * @returns {Array} An array of processed table objects.
77
+ */
78
+ function getAllTables(restaurantData, selectedZitplaats) {
79
+ let allTables = [];
80
+ if (restaurantData?.floors && Array.isArray(restaurantData.floors)) {
81
+ // If a zitplaats is specified and has a floor link, only use that floor
82
+ let floorsToUse = restaurantData.floors;
83
+ if (selectedZitplaats) {
84
+ const linkedFloorId = getFloorIdForSeatPlace(restaurantData, selectedZitplaats);
85
+ if (linkedFloorId) {
86
+ const linkedFloor = restaurantData.floors.find(f => f.id === linkedFloorId);
87
+ if (linkedFloor) {
88
+ floorsToUse = [linkedFloor];
89
+ console.log(`[getAllTables] Floor link found: zitplaats '${selectedZitplaats}' -> floor '${linkedFloorId}'`);
90
+ }
91
+ }
92
+ }
93
+
94
+ floorsToUse.forEach(floor => {
95
+ if (floor?.tables && Array.isArray(floor.tables)) {
96
+ floor.tables.forEach(tbl => {
97
+ // Ensure table number, capacities, priority exist before parsing
98
+ const tableNumberRaw = tbl.tableNumber?.$numberInt ?? tbl.tableNumber;
99
+ const minCapacityRaw = tbl.minCapacity?.$numberInt ?? tbl.minCapacity;
100
+ const maxCapacityRaw = tbl.maxCapacity?.$numberInt ?? tbl.maxCapacity;
101
+ const priorityRaw = tbl.priority?.$numberInt ?? tbl.priority;
102
+ const xRaw = tbl.x?.$numberInt ?? tbl.x;
103
+ const yRaw = tbl.y?.$numberInt ?? tbl.y;
104
+
105
+ if (tbl.objectType === "Tafel" &&
106
+ tableNumberRaw !== undefined &&
107
+ minCapacityRaw !== undefined &&
108
+ maxCapacityRaw !== undefined &&
109
+ priorityRaw !== undefined &&
110
+ xRaw !== undefined &&
111
+ yRaw !== undefined)
112
+ {
113
+ allTables.push({
114
+ tableId: tbl.id,
115
+ tableNumber: parseInt(tableNumberRaw, 10),
116
+ minCapacity: parseInt(minCapacityRaw, 10),
117
+ maxCapacity: parseInt(maxCapacityRaw, 10),
118
+ priority: parseInt(priorityRaw, 10),
119
+ x: parseInt(xRaw, 10),
120
+ y: parseInt(yRaw, 10),
121
+ isTemporary: tbl.isTemporary === true, // Ensure boolean
122
+ startDate: tbl.startDate || null, // Expects 'YYYY-MM-DD'
123
+ endDate: tbl.endDate || null, // Expects 'YYYY-MM-DD'
124
+ application: tbl.application || null // Expects 'breakfast', 'lunch', or 'dinner'
125
+ });
126
+ } else if (tbl.objectType === "Tafel") {
127
+ console.warn(`Skipping table due to missing essential properties: ${JSON.stringify(tbl)}`);
128
+ }
129
+ });
130
+ }
131
+ });
132
+ } else {
133
+ console.warn("Restaurant data is missing 'floors' array.");
134
+ }
135
+
136
+ // Sort tables
137
+ allTables.sort((a, b) => {
138
+ if (a.maxCapacity !== b.maxCapacity) {
139
+ return a.maxCapacity - b.maxCapacity;
140
+ }
141
+ if (a.priority !== b.priority) {
142
+ // Assuming lower priority number means higher priority
143
+ return a.priority - b.priority;
144
+ }
145
+ return a.minCapacity - b.minCapacity;
146
+ });
147
+
148
+ // Filter out tables where parsing failed (resulted in NaN)
149
+ allTables = allTables.filter(t =>
150
+ !isNaN(t.tableNumber) &&
151
+ !isNaN(t.minCapacity) &&
152
+ !isNaN(t.maxCapacity) &&
153
+ !isNaN(t.priority) &&
154
+ !isNaN(t.x) &&
155
+ !isNaN(t.y)
156
+ );
157
+
158
+ return allTables;
159
+ }
160
+
161
+
162
+ // --- Temporary Table Validation ---
163
+
164
+ /**
165
+ * Checks if a temporary table is valid for a specific reservation date and time.
166
+ * @param {Object} table - The table object (must include isTemporary, startDate, endDate, application).
167
+ * @param {string} reservationDateStr - The date of the reservation ("YYYY-MM-DD").
168
+ * @param {string} reservationTimeStr - The time of the reservation ("HH:MM").
169
+ * @returns {boolean} True if the table is valid, false otherwise.
170
+ */
171
+ function isTemporaryTableValid(table, reservationDateStr, reservationTimeStr) {
172
+ if (!table.isTemporary) {
173
+ return true; // Not temporary, always valid (subject to other checks like availability)
174
+ }
175
+
176
+ // Check date range
177
+ if (!table.startDate || !table.endDate) {
178
+ console.log(`Temporary Table ${table.tableNumber} skipped: Missing start/end date.`);
179
+ return false; // Invalid temporary table definition
180
+ }
181
+ // Basic date string comparison (YYYY-MM-DD format)
182
+ if (reservationDateStr < table.startDate || reservationDateStr > table.endDate) {
183
+ // console.log(`Temporary Table ${table.tableNumber} skipped: Date ${reservationDateStr} outside range ${table.startDate}-${table.endDate}.`); // Optional verbose logging
184
+ return false;
185
+ }
186
+
187
+ // Check application (meal type/shift)
188
+ const reservationMealType = getMealTypeByTime(reservationTimeStr);
189
+ if (!reservationMealType) {
190
+ console.log(`Temporary Table ${table.tableNumber} skipped: Could not determine meal type for time ${reservationTimeStr}.`);
191
+ return false; // Cannot determine meal type for the reservation
192
+ }
193
+ if (table.application !== reservationMealType) {
194
+ // console.log(`Temporary Table ${table.tableNumber} skipped: Application '${table.application}' does not match reservation meal type '${reservationMealType}'.`); // Optional verbose logging
195
+ return false;
196
+ }
197
+
198
+ // console.log(`Temporary Table ${table.tableNumber} is valid for ${reservationDateStr} at ${reservationTimeStr} (${reservationMealType}).`); // Optional verbose logging
199
+ return true;
200
+ }
201
+
202
+
203
+ // --- Exports ---
204
+ // Use CommonJS exports (adjust if using ES6 modules)
205
+ module.exports = {
206
+ shifts,
207
+ parseTime,
208
+ getMealTypeByTime,
209
+ getAllTables,
210
+ getFloorIdForSeatPlace,
211
+ isTemporaryTableValid
212
+ };
@@ -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;