@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.
- package/.github/workflows/ci-cd.yml +80 -80
- package/CHANGELOG.md +8 -8
- package/RESERVERINGEN_GIDS.md +986 -986
- package/assignTables.js +444 -444
- package/bundle_entry.js +100 -0
- 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 +15 -15
- package/changes/2025/December/PR5___.md +15 -15
- package/changes/2025/December/PR6__del_.md +17 -17
- package/changes/2025/December/PR7_add__change.md +21 -21
- package/changes/2026/February/PR15_add__change.md +21 -21
- package/changes/2026/January/PR10_add__change.md +21 -21
- package/changes/2026/January/PR11_add__change.md +19 -19
- package/changes/2026/January/PR12_add__.md +21 -21
- package/changes/2026/January/PR13_add__change.md +20 -20
- package/changes/2026/January/PR14_add__change.md +19 -19
- package/changes/2026/January/PR8_add__change.md +38 -38
- package/changes/2026/January/PR9_add__change.md +19 -19
- package/filters/maxArrivalsFilter.js +114 -114
- package/filters/maxGroupsFilter.js +221 -221
- package/filters/timeFilter.js +89 -89
- package/getAvailableTimeblocks.js +170 -158
- package/grouping.js +162 -162
- package/index.js +42 -43
- package/isDateAvailable.js +80 -80
- package/isDateAvailableWithTableCheck.js +172 -172
- package/isTimeAvailable.js +26 -26
- package/moment-timezone-shim.js +179 -0
- package/nul +0 -0
- package/package.json +27 -27
- package/processing/dailyGuestCounts.js +73 -73
- package/processing/mealTypeCount.js +133 -133
- package/processing/timeblocksAvailable.js +194 -182
- package/reservation_data/counter.js +74 -74
- package/restaurant_data/exceptions.js +150 -150
- package/restaurant_data/openinghours.js +166 -142
- package/simulateTableAssignment.js +727 -726
- package/tableHelpers.js +212 -209
- 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
- package/changes/2026/February/PR16_add_getDateClosingReasons.md +0 -31
- package/getDateClosingReasons.js +0 -193
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// Minimal moment-timezone shim for Europe/Brussels only
|
|
2
|
+
// Replaces the full ~500KB moment-timezone library
|
|
3
|
+
// Implements only the subset used by @happychef/algorithm
|
|
4
|
+
|
|
5
|
+
const TIMEZONE = 'Europe/Brussels';
|
|
6
|
+
|
|
7
|
+
// EU DST rules: CET (UTC+1) / CEST (UTC+2)
|
|
8
|
+
// CEST starts last Sunday of March at 02:00 UTC
|
|
9
|
+
// CET starts last Sunday of October at 03:00 UTC
|
|
10
|
+
function getBrusselsOffset(date) {
|
|
11
|
+
const year = date.getUTCFullYear();
|
|
12
|
+
const month = date.getUTCMonth(); // 0-indexed
|
|
13
|
+
|
|
14
|
+
// Find last Sunday of March
|
|
15
|
+
const marchLast = new Date(Date.UTC(year, 2, 31));
|
|
16
|
+
const marchSunday = 31 - marchLast.getUTCDay();
|
|
17
|
+
const dstStart = Date.UTC(year, 2, marchSunday, 1, 0, 0); // 02:00 CET = 01:00 UTC
|
|
18
|
+
|
|
19
|
+
// Find last Sunday of October
|
|
20
|
+
const octLast = new Date(Date.UTC(year, 9, 31));
|
|
21
|
+
const octSunday = 31 - octLast.getUTCDay();
|
|
22
|
+
const dstEnd = Date.UTC(year, 9, octSunday, 1, 0, 0); // 03:00 CEST = 01:00 UTC
|
|
23
|
+
|
|
24
|
+
const ts = date.getTime();
|
|
25
|
+
if (ts >= dstStart && ts < dstEnd) {
|
|
26
|
+
return 2; // CEST (UTC+2)
|
|
27
|
+
}
|
|
28
|
+
return 1; // CET (UTC+1)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function toBrusselsDate(date) {
|
|
32
|
+
const offset = getBrusselsOffset(date);
|
|
33
|
+
return new Date(date.getTime() + offset * 60 * 60 * 1000);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function createMomentObject(date, offset) {
|
|
37
|
+
const brusselsDate = new Date(date.getTime() + offset * 60 * 60 * 1000);
|
|
38
|
+
|
|
39
|
+
const obj = {
|
|
40
|
+
_date: date,
|
|
41
|
+
_brusselsDate: brusselsDate,
|
|
42
|
+
_offset: offset,
|
|
43
|
+
_valid: true,
|
|
44
|
+
|
|
45
|
+
isValid() {
|
|
46
|
+
return this._valid;
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
day() {
|
|
50
|
+
return this._brusselsDate.getUTCDay();
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
hours() {
|
|
54
|
+
return this._brusselsDate.getUTCHours();
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
minutes() {
|
|
58
|
+
return this._brusselsDate.getUTCMinutes();
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
format(fmt) {
|
|
62
|
+
if (fmt === 'YYYY-MM-DD') {
|
|
63
|
+
const y = this._brusselsDate.getUTCFullYear();
|
|
64
|
+
const m = String(this._brusselsDate.getUTCMonth() + 1).padStart(2, '0');
|
|
65
|
+
const d = String(this._brusselsDate.getUTCDate()).padStart(2, '0');
|
|
66
|
+
return `${y}-${m}-${d}`;
|
|
67
|
+
}
|
|
68
|
+
if (fmt === 'HH:mm') {
|
|
69
|
+
const h = String(this._brusselsDate.getUTCHours()).padStart(2, '0');
|
|
70
|
+
const min = String(this._brusselsDate.getUTCMinutes()).padStart(2, '0');
|
|
71
|
+
return `${h}:${min}`;
|
|
72
|
+
}
|
|
73
|
+
return this._brusselsDate.toISOString();
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
startOf(unit) {
|
|
77
|
+
if (unit === 'day') {
|
|
78
|
+
const d = new Date(Date.UTC(
|
|
79
|
+
this._brusselsDate.getUTCFullYear(),
|
|
80
|
+
this._brusselsDate.getUTCMonth(),
|
|
81
|
+
this._brusselsDate.getUTCDate(),
|
|
82
|
+
0, 0, 0, 0
|
|
83
|
+
));
|
|
84
|
+
// Adjust back from Brussels to UTC
|
|
85
|
+
const utcDate = new Date(d.getTime() - this._offset * 60 * 60 * 1000);
|
|
86
|
+
return createMomentObject(utcDate, this._offset);
|
|
87
|
+
}
|
|
88
|
+
return this;
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
endOf(unit) {
|
|
92
|
+
if (unit === 'day') {
|
|
93
|
+
const d = new Date(Date.UTC(
|
|
94
|
+
this._brusselsDate.getUTCFullYear(),
|
|
95
|
+
this._brusselsDate.getUTCMonth(),
|
|
96
|
+
this._brusselsDate.getUTCDate(),
|
|
97
|
+
23, 59, 59, 999
|
|
98
|
+
));
|
|
99
|
+
const utcDate = new Date(d.getTime() - this._offset * 60 * 60 * 1000);
|
|
100
|
+
return createMomentObject(utcDate, this._offset);
|
|
101
|
+
}
|
|
102
|
+
return this;
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
isBefore(other) {
|
|
106
|
+
return this._date.getTime() < other._date.getTime();
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
isAfter(other) {
|
|
110
|
+
return this._date.getTime() > other._date.getTime();
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
tz() {
|
|
114
|
+
// Already in Brussels timezone, return self
|
|
115
|
+
return this;
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
return obj;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function parseDateStr(dateStr, format) {
|
|
123
|
+
if (format === 'YYYY-MM-DD') {
|
|
124
|
+
const parts = dateStr.split('-');
|
|
125
|
+
if (parts.length !== 3) return null;
|
|
126
|
+
const year = parseInt(parts[0], 10);
|
|
127
|
+
const month = parseInt(parts[1], 10) - 1;
|
|
128
|
+
const day = parseInt(parts[2], 10);
|
|
129
|
+
if (isNaN(year) || isNaN(month) || isNaN(day)) return null;
|
|
130
|
+
if (month < 0 || month > 11 || day < 1 || day > 31) return null;
|
|
131
|
+
// Create date at midnight Brussels time -> convert to UTC
|
|
132
|
+
const utcDate = new Date(Date.UTC(year, month, day, 0, 0, 0));
|
|
133
|
+
return utcDate;
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Main moment function
|
|
139
|
+
function moment(dateStr, format, timezone) {
|
|
140
|
+
if (dateStr === undefined || dateStr === null) {
|
|
141
|
+
// moment() - current time
|
|
142
|
+
const now = new Date();
|
|
143
|
+
const offset = getBrusselsOffset(now);
|
|
144
|
+
const obj = createMomentObject(now, offset);
|
|
145
|
+
obj.tz = function() { return obj; };
|
|
146
|
+
return obj;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (typeof dateStr === 'string') {
|
|
150
|
+
const date = parseDateStr(dateStr, format || 'YYYY-MM-DD');
|
|
151
|
+
if (!date) {
|
|
152
|
+
return { _valid: false, isValid() { return false; }, day() { return 0; }, tz() { return this; } };
|
|
153
|
+
}
|
|
154
|
+
const offset = getBrusselsOffset(date);
|
|
155
|
+
return createMomentObject(date, offset);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Fallback
|
|
159
|
+
const now = new Date();
|
|
160
|
+
const offset = getBrusselsOffset(now);
|
|
161
|
+
return createMomentObject(now, offset);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// moment.tz(dateStr, format, timezone) or moment().tz(timezone)
|
|
165
|
+
moment.tz = function(dateStr, format, timezone) {
|
|
166
|
+
if (typeof dateStr === 'string' && typeof format === 'string' && typeof timezone === 'string') {
|
|
167
|
+
// moment.tz(dateStr, format, timezone)
|
|
168
|
+
return moment(dateStr, format, timezone);
|
|
169
|
+
}
|
|
170
|
+
if (typeof dateStr === 'string' && typeof format === 'string' && timezone === undefined) {
|
|
171
|
+
// moment.tz(dateStr, timezone) - dateStr is actual date, format is timezone
|
|
172
|
+
// This pattern: moment().tz('Europe/Brussels')
|
|
173
|
+
return moment(dateStr, 'YYYY-MM-DD');
|
|
174
|
+
}
|
|
175
|
+
// Fallback: current time in Brussels
|
|
176
|
+
return moment();
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
module.exports = moment;
|
package/nul
ADDED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@happychef/algorithm",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "Restaurant and reservation algorithm utilities",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "jest",
|
|
8
|
-
"test:watch": "jest --watch",
|
|
9
|
-
"test:coverage": "jest --coverage"
|
|
10
|
-
},
|
|
11
|
-
"author": "happy chef",
|
|
12
|
-
"license": "MIT",
|
|
13
|
-
"private": false,
|
|
14
|
-
"keywords": [
|
|
15
|
-
"algorithm",
|
|
16
|
-
"restaurant",
|
|
17
|
-
"reservation",
|
|
18
|
-
"utilities"
|
|
19
|
-
],
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"moment-timezone": "^0.6.0"
|
|
22
|
-
},
|
|
23
|
-
"devDependencies": {
|
|
24
|
-
"@types/jest": "^30.0.0",
|
|
25
|
-
"jest": "^30.2.0"
|
|
26
|
-
}
|
|
27
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@happychef/algorithm",
|
|
3
|
+
"version": "1.3.5",
|
|
4
|
+
"description": "Restaurant and reservation algorithm utilities",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "jest",
|
|
8
|
+
"test:watch": "jest --watch",
|
|
9
|
+
"test:coverage": "jest --coverage"
|
|
10
|
+
},
|
|
11
|
+
"author": "happy chef",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"private": false,
|
|
14
|
+
"keywords": [
|
|
15
|
+
"algorithm",
|
|
16
|
+
"restaurant",
|
|
17
|
+
"reservation",
|
|
18
|
+
"utilities"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"moment-timezone": "^0.6.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/jest": "^30.0.0",
|
|
25
|
+
"jest": "^30.2.0"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
// dailyGuestCounts.js
|
|
2
|
-
|
|
3
|
-
const { getGuestCountsForMeal } = require('./mealTypeCount');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Calculates guest counts for breakfast, lunch, and dinner, and combines the results into a flat object.
|
|
7
|
-
* If time slots overlap, the available seats from the latest meal (dinner > lunch > breakfast) are used.
|
|
8
|
-
* @param {Object} data - The main data object.
|
|
9
|
-
* @param {string} dateStr - The date string (YYYY-MM-DD).
|
|
10
|
-
* @param {Array} reservations - An array of reservation objects.
|
|
11
|
-
* @returns {Object} An object containing combined guest counts for all meals with time slots as keys,
|
|
12
|
-
* and an array of shiftsInfo containing shift details.
|
|
13
|
-
*/
|
|
14
|
-
function getDailyGuestCounts(data, dateStr, reservations) {
|
|
15
|
-
// Define meal types in order of priority (lowest to highest)
|
|
16
|
-
const mealTypes = ['breakfast', 'lunch', 'dinner'];
|
|
17
|
-
const combinedGuestCounts = {};
|
|
18
|
-
const shiftsInfo = [];
|
|
19
|
-
const mealPriority = {
|
|
20
|
-
'breakfast': 1,
|
|
21
|
-
'lunch': 2,
|
|
22
|
-
'dinner': 3
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
for (const mealType of mealTypes) {
|
|
26
|
-
const result = getGuestCountsForMeal(data, dateStr, mealType, reservations);
|
|
27
|
-
if (result) {
|
|
28
|
-
const { guestCounts, shiftsInfo: mealShiftsInfo } = result;
|
|
29
|
-
|
|
30
|
-
// Merge guestCounts into combinedGuestCounts
|
|
31
|
-
for (const [time, availableSeats] of Object.entries(guestCounts)) {
|
|
32
|
-
if (combinedGuestCounts.hasOwnProperty(time)) {
|
|
33
|
-
// Compare meal priorities
|
|
34
|
-
const existingMealPriority = combinedGuestCounts[time].mealPriority;
|
|
35
|
-
const currentMealPriority = mealPriority[mealType];
|
|
36
|
-
|
|
37
|
-
if (currentMealPriority >= existingMealPriority) {
|
|
38
|
-
// Update with the current meal's available seats and priority
|
|
39
|
-
combinedGuestCounts[time] = {
|
|
40
|
-
availableSeats,
|
|
41
|
-
mealPriority: currentMealPriority
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
// Else, keep the existing value
|
|
45
|
-
} else {
|
|
46
|
-
// Add new time slot with available seats and meal priority
|
|
47
|
-
combinedGuestCounts[time] = {
|
|
48
|
-
availableSeats,
|
|
49
|
-
mealPriority: mealPriority[mealType]
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Merge shiftsInfo
|
|
55
|
-
if (mealShiftsInfo && mealShiftsInfo.length > 0) {
|
|
56
|
-
shiftsInfo.push(...mealShiftsInfo);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
// Else do nothing if the meal is not available
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Extract only the availableSeats for the final output
|
|
63
|
-
const finalGuestCounts = {};
|
|
64
|
-
for (const [time, data] of Object.entries(combinedGuestCounts)) {
|
|
65
|
-
finalGuestCounts[time] = data.availableSeats;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return { guestCounts: finalGuestCounts, shiftsInfo };
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
module.exports = {
|
|
72
|
-
getDailyGuestCounts,
|
|
73
|
-
};
|
|
1
|
+
// dailyGuestCounts.js
|
|
2
|
+
|
|
3
|
+
const { getGuestCountsForMeal } = require('./mealTypeCount');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Calculates guest counts for breakfast, lunch, and dinner, and combines the results into a flat object.
|
|
7
|
+
* If time slots overlap, the available seats from the latest meal (dinner > lunch > breakfast) are used.
|
|
8
|
+
* @param {Object} data - The main data object.
|
|
9
|
+
* @param {string} dateStr - The date string (YYYY-MM-DD).
|
|
10
|
+
* @param {Array} reservations - An array of reservation objects.
|
|
11
|
+
* @returns {Object} An object containing combined guest counts for all meals with time slots as keys,
|
|
12
|
+
* and an array of shiftsInfo containing shift details.
|
|
13
|
+
*/
|
|
14
|
+
function getDailyGuestCounts(data, dateStr, reservations) {
|
|
15
|
+
// Define meal types in order of priority (lowest to highest)
|
|
16
|
+
const mealTypes = ['breakfast', 'lunch', 'dinner'];
|
|
17
|
+
const combinedGuestCounts = {};
|
|
18
|
+
const shiftsInfo = [];
|
|
19
|
+
const mealPriority = {
|
|
20
|
+
'breakfast': 1,
|
|
21
|
+
'lunch': 2,
|
|
22
|
+
'dinner': 3
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
for (const mealType of mealTypes) {
|
|
26
|
+
const result = getGuestCountsForMeal(data, dateStr, mealType, reservations);
|
|
27
|
+
if (result) {
|
|
28
|
+
const { guestCounts, shiftsInfo: mealShiftsInfo } = result;
|
|
29
|
+
|
|
30
|
+
// Merge guestCounts into combinedGuestCounts
|
|
31
|
+
for (const [time, availableSeats] of Object.entries(guestCounts)) {
|
|
32
|
+
if (combinedGuestCounts.hasOwnProperty(time)) {
|
|
33
|
+
// Compare meal priorities
|
|
34
|
+
const existingMealPriority = combinedGuestCounts[time].mealPriority;
|
|
35
|
+
const currentMealPriority = mealPriority[mealType];
|
|
36
|
+
|
|
37
|
+
if (currentMealPriority >= existingMealPriority) {
|
|
38
|
+
// Update with the current meal's available seats and priority
|
|
39
|
+
combinedGuestCounts[time] = {
|
|
40
|
+
availableSeats,
|
|
41
|
+
mealPriority: currentMealPriority
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// Else, keep the existing value
|
|
45
|
+
} else {
|
|
46
|
+
// Add new time slot with available seats and meal priority
|
|
47
|
+
combinedGuestCounts[time] = {
|
|
48
|
+
availableSeats,
|
|
49
|
+
mealPriority: mealPriority[mealType]
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Merge shiftsInfo
|
|
55
|
+
if (mealShiftsInfo && mealShiftsInfo.length > 0) {
|
|
56
|
+
shiftsInfo.push(...mealShiftsInfo);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Else do nothing if the meal is not available
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Extract only the availableSeats for the final output
|
|
63
|
+
const finalGuestCounts = {};
|
|
64
|
+
for (const [time, data] of Object.entries(combinedGuestCounts)) {
|
|
65
|
+
finalGuestCounts[time] = data.availableSeats;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return { guestCounts: finalGuestCounts, shiftsInfo };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = {
|
|
72
|
+
getDailyGuestCounts,
|
|
73
|
+
};
|
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
// mealTypeCount.js
|
|
2
|
-
|
|
3
|
-
const { getDataByDateAndMealWithExceptions } = require('../restaurant_data/exceptions');
|
|
4
|
-
const { parseTime } = require('../restaurant_data/openinghours');
|
|
5
|
-
const { getGuestCountAtHour } = require('../reservation_data/counter');
|
|
6
|
-
|
|
7
|
-
function getInterval(data) {
|
|
8
|
-
let intervalReservatie = 15;
|
|
9
|
-
if (
|
|
10
|
-
data['general-settings'] &&
|
|
11
|
-
data['general-settings'].intervalReservatie &&
|
|
12
|
-
parseInt(data['general-settings'].intervalReservatie, 10) > 0
|
|
13
|
-
) {
|
|
14
|
-
intervalReservatie = parseInt(data['general-settings'].intervalReservatie, 10);
|
|
15
|
-
}
|
|
16
|
-
return intervalReservatie;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Retrieves meal types with shifts enabled and at least one shift defined for the specified date.
|
|
21
|
-
* @param {Object} data - The main data object.
|
|
22
|
-
* @param {string} dateStr - The date string (YYYY-MM-DD).
|
|
23
|
-
* @returns {Array} - An array of meal types with shifts.
|
|
24
|
-
*/
|
|
25
|
-
function getMealTypesWithShifts(data, dateStr) {
|
|
26
|
-
const mealTypes = ['breakfast', 'lunch', 'dinner'];
|
|
27
|
-
const mealTypesWithShifts = [];
|
|
28
|
-
|
|
29
|
-
for (const mealType of mealTypes) {
|
|
30
|
-
const mealData = getDataByDateAndMealWithExceptions(data, dateStr, mealType);
|
|
31
|
-
if (
|
|
32
|
-
mealData &&
|
|
33
|
-
mealData.shiftsEnabled &&
|
|
34
|
-
Array.isArray(mealData.shifts) &&
|
|
35
|
-
mealData.shifts.length > 0
|
|
36
|
-
) {
|
|
37
|
-
mealTypesWithShifts.push(mealType);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return mealTypesWithShifts;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function shouldIncludeEndTime(mealType, endTime) {
|
|
45
|
-
if ((mealType === 'breakfast' && endTime === '11:00') ||
|
|
46
|
-
(mealType === 'lunch' && endTime === '16:00')) {
|
|
47
|
-
return false; // Do not include endTime for breakfast at 11:00 and lunch at 16:00
|
|
48
|
-
}
|
|
49
|
-
return true; // Include endTime for all other cases
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Calculates guest counts for each interval during a meal period or at shift times.
|
|
54
|
-
* @param {Object} data - The main data object.
|
|
55
|
-
* @param {string} dateStr - The date string (YYYY-MM-DD).
|
|
56
|
-
* @param {string} mealType - The meal type ("breakfast", "lunch", "dinner").
|
|
57
|
-
* @param {Array} reservations - An array of reservation objects.
|
|
58
|
-
* @returns {Object|null} An object mapping times to guest counts, or null if meal is not available.
|
|
59
|
-
*/
|
|
60
|
-
function getGuestCountsForMeal(data, dateStr, mealType, reservations) {
|
|
61
|
-
const mealData = getDataByDateAndMealWithExceptions(data, dateStr, mealType);
|
|
62
|
-
if (!mealData) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const guestCounts = {};
|
|
67
|
-
const shiftsInfo = [];
|
|
68
|
-
|
|
69
|
-
// Get 'intervalReservatie' from general settings, default to 15 if not set or zero
|
|
70
|
-
let intervalReservatie = getInterval(data);
|
|
71
|
-
|
|
72
|
-
// Check if shifts are enabled and shifts array has valid content
|
|
73
|
-
if (
|
|
74
|
-
mealData.shiftsEnabled &&
|
|
75
|
-
Array.isArray(mealData.shifts) &&
|
|
76
|
-
mealData.shifts.length > 0
|
|
77
|
-
) {
|
|
78
|
-
// If shifts are enabled and valid, calculate guest counts at shift times
|
|
79
|
-
const shifts = mealData.shifts; // Array of shifts
|
|
80
|
-
|
|
81
|
-
for (const shift of shifts) {
|
|
82
|
-
const timeStr = shift.time; // Time of the shift in "HH:MM" format
|
|
83
|
-
|
|
84
|
-
// Get guest count at this time
|
|
85
|
-
const guestCount = getGuestCountAtHour(data, reservations, timeStr, dateStr);
|
|
86
|
-
|
|
87
|
-
// Store in guestCounts
|
|
88
|
-
guestCounts[timeStr] = mealData.maxCapacity - guestCount;
|
|
89
|
-
|
|
90
|
-
// Store shift information
|
|
91
|
-
shiftsInfo.push({
|
|
92
|
-
mealType,
|
|
93
|
-
shiftName: shift.name,
|
|
94
|
-
time: timeStr,
|
|
95
|
-
availableSeats: mealData.maxCapacity - guestCount,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
// If shifts are not enabled or shifts array is empty/invalid, calculate guest counts at intervals
|
|
100
|
-
const startTime = mealData.startTime;
|
|
101
|
-
const endTime = mealData.endTime;
|
|
102
|
-
|
|
103
|
-
// Determine if endTime should be included
|
|
104
|
-
const includeEndTime = shouldIncludeEndTime(mealType, endTime);
|
|
105
|
-
|
|
106
|
-
// Convert startTime and endTime to minutes since midnight
|
|
107
|
-
let currentTime = parseTime(startTime);
|
|
108
|
-
const endTimeMinutes = parseTime(endTime);
|
|
109
|
-
|
|
110
|
-
while (includeEndTime ? currentTime <= endTimeMinutes : currentTime < endTimeMinutes) {
|
|
111
|
-
// Convert currentTime back to "HH:MM" format
|
|
112
|
-
const hours = Math.floor(currentTime / 60).toString().padStart(2, '0');
|
|
113
|
-
const minutes = (currentTime % 60).toString().padStart(2, '0');
|
|
114
|
-
const timeStr = `${hours}:${minutes}`;
|
|
115
|
-
|
|
116
|
-
// Get guest count at this time
|
|
117
|
-
const guestCount = getGuestCountAtHour(data, reservations, timeStr, dateStr);
|
|
118
|
-
|
|
119
|
-
// Store in guestCounts
|
|
120
|
-
guestCounts[timeStr] = mealData.maxCapacity - guestCount;
|
|
121
|
-
|
|
122
|
-
// Increment currentTime by 'intervalReservatie' minutes
|
|
123
|
-
currentTime += intervalReservatie;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return { guestCounts, shiftsInfo };
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
module.exports = {
|
|
131
|
-
getGuestCountsForMeal,
|
|
132
|
-
getMealTypesWithShifts, // Exported
|
|
133
|
-
};
|
|
1
|
+
// mealTypeCount.js
|
|
2
|
+
|
|
3
|
+
const { getDataByDateAndMealWithExceptions } = require('../restaurant_data/exceptions');
|
|
4
|
+
const { parseTime } = require('../restaurant_data/openinghours');
|
|
5
|
+
const { getGuestCountAtHour } = require('../reservation_data/counter');
|
|
6
|
+
|
|
7
|
+
function getInterval(data) {
|
|
8
|
+
let intervalReservatie = 15;
|
|
9
|
+
if (
|
|
10
|
+
data['general-settings'] &&
|
|
11
|
+
data['general-settings'].intervalReservatie &&
|
|
12
|
+
parseInt(data['general-settings'].intervalReservatie, 10) > 0
|
|
13
|
+
) {
|
|
14
|
+
intervalReservatie = parseInt(data['general-settings'].intervalReservatie, 10);
|
|
15
|
+
}
|
|
16
|
+
return intervalReservatie;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves meal types with shifts enabled and at least one shift defined for the specified date.
|
|
21
|
+
* @param {Object} data - The main data object.
|
|
22
|
+
* @param {string} dateStr - The date string (YYYY-MM-DD).
|
|
23
|
+
* @returns {Array} - An array of meal types with shifts.
|
|
24
|
+
*/
|
|
25
|
+
function getMealTypesWithShifts(data, dateStr) {
|
|
26
|
+
const mealTypes = ['breakfast', 'lunch', 'dinner'];
|
|
27
|
+
const mealTypesWithShifts = [];
|
|
28
|
+
|
|
29
|
+
for (const mealType of mealTypes) {
|
|
30
|
+
const mealData = getDataByDateAndMealWithExceptions(data, dateStr, mealType);
|
|
31
|
+
if (
|
|
32
|
+
mealData &&
|
|
33
|
+
mealData.shiftsEnabled &&
|
|
34
|
+
Array.isArray(mealData.shifts) &&
|
|
35
|
+
mealData.shifts.length > 0
|
|
36
|
+
) {
|
|
37
|
+
mealTypesWithShifts.push(mealType);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return mealTypesWithShifts;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function shouldIncludeEndTime(mealType, endTime) {
|
|
45
|
+
if ((mealType === 'breakfast' && endTime === '11:00') ||
|
|
46
|
+
(mealType === 'lunch' && endTime === '16:00')) {
|
|
47
|
+
return false; // Do not include endTime for breakfast at 11:00 and lunch at 16:00
|
|
48
|
+
}
|
|
49
|
+
return true; // Include endTime for all other cases
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Calculates guest counts for each interval during a meal period or at shift times.
|
|
54
|
+
* @param {Object} data - The main data object.
|
|
55
|
+
* @param {string} dateStr - The date string (YYYY-MM-DD).
|
|
56
|
+
* @param {string} mealType - The meal type ("breakfast", "lunch", "dinner").
|
|
57
|
+
* @param {Array} reservations - An array of reservation objects.
|
|
58
|
+
* @returns {Object|null} An object mapping times to guest counts, or null if meal is not available.
|
|
59
|
+
*/
|
|
60
|
+
function getGuestCountsForMeal(data, dateStr, mealType, reservations) {
|
|
61
|
+
const mealData = getDataByDateAndMealWithExceptions(data, dateStr, mealType);
|
|
62
|
+
if (!mealData) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const guestCounts = {};
|
|
67
|
+
const shiftsInfo = [];
|
|
68
|
+
|
|
69
|
+
// Get 'intervalReservatie' from general settings, default to 15 if not set or zero
|
|
70
|
+
let intervalReservatie = getInterval(data);
|
|
71
|
+
|
|
72
|
+
// Check if shifts are enabled and shifts array has valid content
|
|
73
|
+
if (
|
|
74
|
+
mealData.shiftsEnabled &&
|
|
75
|
+
Array.isArray(mealData.shifts) &&
|
|
76
|
+
mealData.shifts.length > 0
|
|
77
|
+
) {
|
|
78
|
+
// If shifts are enabled and valid, calculate guest counts at shift times
|
|
79
|
+
const shifts = mealData.shifts; // Array of shifts
|
|
80
|
+
|
|
81
|
+
for (const shift of shifts) {
|
|
82
|
+
const timeStr = shift.time; // Time of the shift in "HH:MM" format
|
|
83
|
+
|
|
84
|
+
// Get guest count at this time
|
|
85
|
+
const guestCount = getGuestCountAtHour(data, reservations, timeStr, dateStr);
|
|
86
|
+
|
|
87
|
+
// Store in guestCounts
|
|
88
|
+
guestCounts[timeStr] = mealData.maxCapacity - guestCount;
|
|
89
|
+
|
|
90
|
+
// Store shift information
|
|
91
|
+
shiftsInfo.push({
|
|
92
|
+
mealType,
|
|
93
|
+
shiftName: shift.name,
|
|
94
|
+
time: timeStr,
|
|
95
|
+
availableSeats: mealData.maxCapacity - guestCount,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
// If shifts are not enabled or shifts array is empty/invalid, calculate guest counts at intervals
|
|
100
|
+
const startTime = mealData.startTime;
|
|
101
|
+
const endTime = mealData.endTime;
|
|
102
|
+
|
|
103
|
+
// Determine if endTime should be included
|
|
104
|
+
const includeEndTime = shouldIncludeEndTime(mealType, endTime);
|
|
105
|
+
|
|
106
|
+
// Convert startTime and endTime to minutes since midnight
|
|
107
|
+
let currentTime = parseTime(startTime);
|
|
108
|
+
const endTimeMinutes = parseTime(endTime);
|
|
109
|
+
|
|
110
|
+
while (includeEndTime ? currentTime <= endTimeMinutes : currentTime < endTimeMinutes) {
|
|
111
|
+
// Convert currentTime back to "HH:MM" format
|
|
112
|
+
const hours = Math.floor(currentTime / 60).toString().padStart(2, '0');
|
|
113
|
+
const minutes = (currentTime % 60).toString().padStart(2, '0');
|
|
114
|
+
const timeStr = `${hours}:${minutes}`;
|
|
115
|
+
|
|
116
|
+
// Get guest count at this time
|
|
117
|
+
const guestCount = getGuestCountAtHour(data, reservations, timeStr, dateStr);
|
|
118
|
+
|
|
119
|
+
// Store in guestCounts
|
|
120
|
+
guestCounts[timeStr] = mealData.maxCapacity - guestCount;
|
|
121
|
+
|
|
122
|
+
// Increment currentTime by 'intervalReservatie' minutes
|
|
123
|
+
currentTime += intervalReservatie;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return { guestCounts, shiftsInfo };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
module.exports = {
|
|
131
|
+
getGuestCountsForMeal,
|
|
132
|
+
getMealTypesWithShifts, // Exported
|
|
133
|
+
};
|