@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,149 +1,149 @@
|
|
|
1
|
-
// exceptions.js
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
getDataByDateAndMeal,
|
|
5
|
-
getDataByDateAndTime,
|
|
6
|
-
getMealTypeByTime,
|
|
7
|
-
parseTime,
|
|
8
|
-
shifts,
|
|
9
|
-
daysOfWeekEnglish,
|
|
10
|
-
daysOfWeekDutch,
|
|
11
|
-
} = require('./openinghours');
|
|
12
|
-
|
|
13
|
-
function isDateInRange(dateStr, startDateStr, endDateStr) {
|
|
14
|
-
const date = new Date(dateStr);
|
|
15
|
-
const startDate = new Date(startDateStr);
|
|
16
|
-
const endDate = new Date(endDateStr);
|
|
17
|
-
if (isNaN(date) || isNaN(startDate) || isNaN(endDate)) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
return date >= startDate && date <= endDate;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function getDutchDayOfWeek(date) {
|
|
24
|
-
const dayIndex = date.getDay();
|
|
25
|
-
return daysOfWeekDutch[dayIndex];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function doesExceptionApply(exception, dateStr, dateDayOfWeekDutch, mealType) {
|
|
29
|
-
const { timeframe, startDate, endDate, daysOfWeek } = exception;
|
|
30
|
-
|
|
31
|
-
if (!isDateInRange(dateStr, startDate, endDate)) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (Array.isArray(daysOfWeek) && daysOfWeek.length > 0) {
|
|
36
|
-
const daysOfWeekLower = daysOfWeek.map(day => day.toLowerCase());
|
|
37
|
-
if (!daysOfWeekLower.includes(dateDayOfWeekDutch)) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (timeframe === 'Volledige Dag' || timeframe === mealType) {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function getDuurReservatie(data) {
|
|
50
|
-
let duurReservatie = 120;
|
|
51
|
-
if (
|
|
52
|
-
data['general-settings'] &&
|
|
53
|
-
data['general-settings'].duurReservatie &&
|
|
54
|
-
parseInt(data['general-settings'].duurReservatie, 10) > 0
|
|
55
|
-
) {
|
|
56
|
-
duurReservatie = parseInt(data['general-settings'].duurReservatie, 10);
|
|
57
|
-
}
|
|
58
|
-
return duurReservatie;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function addDuurReservatieToEndTime(mealData, data) {
|
|
62
|
-
const duurReservatie = getDuurReservatie(data);
|
|
63
|
-
const endMinutes = parseTime(mealData.endTime);
|
|
64
|
-
const newEndMinutes = endMinutes + duurReservatie;
|
|
65
|
-
const hours = String(Math.floor(newEndMinutes / 60)).padStart(2, '0');
|
|
66
|
-
const minutes = String(newEndMinutes % 60).padStart(2, '0');
|
|
67
|
-
mealData.endTime = `${hours}:${minutes}`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function mapExceptionToMealData(exception, data) {
|
|
71
|
-
let mealData = {
|
|
72
|
-
enabled: true,
|
|
73
|
-
startTime: exception.startHour,
|
|
74
|
-
endTime: exception.endHour,
|
|
75
|
-
maxCapacityEnabled: exception.maxSeats ? true : false,
|
|
76
|
-
maxCapacity: exception.maxSeats || null,
|
|
77
|
-
shiftsEnabled: false,
|
|
78
|
-
shifts: [],
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
// Add duurReservatie to endTime
|
|
82
|
-
addDuurReservatieToEndTime(mealData, data);
|
|
83
|
-
|
|
84
|
-
return mealData;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function getDataByDateAndMealWithExceptions(data, dateStr, mealType) {
|
|
88
|
-
const exceptions = data.exceptions || [];
|
|
89
|
-
const date = new Date(dateStr);
|
|
90
|
-
if (isNaN(date)) {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
const dateDayOfWeekDutch = getDutchDayOfWeek(date).toLowerCase();
|
|
94
|
-
|
|
95
|
-
const exceptionTypesPriority = ['Opening', 'Sluiting', 'Uitzondering'];
|
|
96
|
-
|
|
97
|
-
for (const exceptionType of exceptionTypesPriority) {
|
|
98
|
-
for (const exception of exceptions) {
|
|
99
|
-
if (exception.type === exceptionType) {
|
|
100
|
-
if (doesExceptionApply(exception, dateStr, dateDayOfWeekDutch, mealType)) {
|
|
101
|
-
if (exceptionType === 'Sluiting') {
|
|
102
|
-
return null;
|
|
103
|
-
} else {
|
|
104
|
-
return mapExceptionToMealData(exception, data);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return getDataByDateAndMeal(data, dateStr, mealType);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function shouldIncludeEndTime(mealType, endTime) {
|
|
115
|
-
if ((mealType === 'breakfast' && endTime === '11:00') ||
|
|
116
|
-
(mealType === 'lunch' && endTime === '16:00')) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function getDataByDateAndTimeWithExceptions(data, dateStr, timeStr) {
|
|
123
|
-
const mealType = getMealTypeByTime(timeStr);
|
|
124
|
-
if (!mealType) {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
const mealData = getDataByDateAndMealWithExceptions(data, dateStr, mealType);
|
|
128
|
-
if (!mealData) {
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const requestedTime = parseTime(timeStr);
|
|
133
|
-
const startTime = parseTime(mealData.startTime);
|
|
134
|
-
const endTime = parseTime(mealData.endTime);
|
|
135
|
-
|
|
136
|
-
const includeEndTime = shouldIncludeEndTime(mealType, mealData.endTime);
|
|
137
|
-
|
|
138
|
-
const timeFallsWithin =
|
|
139
|
-
includeEndTime
|
|
140
|
-
? requestedTime >= startTime && requestedTime <= endTime
|
|
141
|
-
: requestedTime >= startTime && requestedTime < endTime;
|
|
142
|
-
|
|
143
|
-
return timeFallsWithin ? mealData : null;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
module.exports = {
|
|
147
|
-
getDataByDateAndMealWithExceptions,
|
|
148
|
-
getDataByDateAndTimeWithExceptions,
|
|
149
|
-
};
|
|
1
|
+
// exceptions.js
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
getDataByDateAndMeal,
|
|
5
|
+
getDataByDateAndTime,
|
|
6
|
+
getMealTypeByTime,
|
|
7
|
+
parseTime,
|
|
8
|
+
shifts,
|
|
9
|
+
daysOfWeekEnglish,
|
|
10
|
+
daysOfWeekDutch,
|
|
11
|
+
} = require('./openinghours');
|
|
12
|
+
|
|
13
|
+
function isDateInRange(dateStr, startDateStr, endDateStr) {
|
|
14
|
+
const date = new Date(dateStr);
|
|
15
|
+
const startDate = new Date(startDateStr);
|
|
16
|
+
const endDate = new Date(endDateStr);
|
|
17
|
+
if (isNaN(date) || isNaN(startDate) || isNaN(endDate)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return date >= startDate && date <= endDate;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getDutchDayOfWeek(date) {
|
|
24
|
+
const dayIndex = date.getDay();
|
|
25
|
+
return daysOfWeekDutch[dayIndex];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function doesExceptionApply(exception, dateStr, dateDayOfWeekDutch, mealType) {
|
|
29
|
+
const { timeframe, startDate, endDate, daysOfWeek } = exception;
|
|
30
|
+
|
|
31
|
+
if (!isDateInRange(dateStr, startDate, endDate)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (Array.isArray(daysOfWeek) && daysOfWeek.length > 0) {
|
|
36
|
+
const daysOfWeekLower = daysOfWeek.map(day => day.toLowerCase());
|
|
37
|
+
if (!daysOfWeekLower.includes(dateDayOfWeekDutch)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (timeframe === 'Volledige Dag' || timeframe === mealType) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getDuurReservatie(data) {
|
|
50
|
+
let duurReservatie = 120;
|
|
51
|
+
if (
|
|
52
|
+
data['general-settings'] &&
|
|
53
|
+
data['general-settings'].duurReservatie &&
|
|
54
|
+
parseInt(data['general-settings'].duurReservatie, 10) > 0
|
|
55
|
+
) {
|
|
56
|
+
duurReservatie = parseInt(data['general-settings'].duurReservatie, 10);
|
|
57
|
+
}
|
|
58
|
+
return duurReservatie;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function addDuurReservatieToEndTime(mealData, data) {
|
|
62
|
+
const duurReservatie = getDuurReservatie(data);
|
|
63
|
+
const endMinutes = parseTime(mealData.endTime);
|
|
64
|
+
const newEndMinutes = endMinutes + duurReservatie;
|
|
65
|
+
const hours = String(Math.floor(newEndMinutes / 60)).padStart(2, '0');
|
|
66
|
+
const minutes = String(newEndMinutes % 60).padStart(2, '0');
|
|
67
|
+
mealData.endTime = `${hours}:${minutes}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function mapExceptionToMealData(exception, data) {
|
|
71
|
+
let mealData = {
|
|
72
|
+
enabled: true,
|
|
73
|
+
startTime: exception.startHour,
|
|
74
|
+
endTime: exception.endHour,
|
|
75
|
+
maxCapacityEnabled: exception.maxSeats ? true : false,
|
|
76
|
+
maxCapacity: exception.maxSeats || null,
|
|
77
|
+
shiftsEnabled: false,
|
|
78
|
+
shifts: [],
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// Add duurReservatie to endTime
|
|
82
|
+
addDuurReservatieToEndTime(mealData, data);
|
|
83
|
+
|
|
84
|
+
return mealData;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function getDataByDateAndMealWithExceptions(data, dateStr, mealType) {
|
|
88
|
+
const exceptions = data.exceptions || [];
|
|
89
|
+
const date = new Date(dateStr);
|
|
90
|
+
if (isNaN(date)) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const dateDayOfWeekDutch = getDutchDayOfWeek(date).toLowerCase();
|
|
94
|
+
|
|
95
|
+
const exceptionTypesPriority = ['Opening', 'Sluiting', 'Uitzondering'];
|
|
96
|
+
|
|
97
|
+
for (const exceptionType of exceptionTypesPriority) {
|
|
98
|
+
for (const exception of exceptions) {
|
|
99
|
+
if (exception.type === exceptionType) {
|
|
100
|
+
if (doesExceptionApply(exception, dateStr, dateDayOfWeekDutch, mealType)) {
|
|
101
|
+
if (exceptionType === 'Sluiting') {
|
|
102
|
+
return null;
|
|
103
|
+
} else {
|
|
104
|
+
return mapExceptionToMealData(exception, data);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return getDataByDateAndMeal(data, dateStr, mealType);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function shouldIncludeEndTime(mealType, endTime) {
|
|
115
|
+
if ((mealType === 'breakfast' && endTime === '11:00') ||
|
|
116
|
+
(mealType === 'lunch' && endTime === '16:00')) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function getDataByDateAndTimeWithExceptions(data, dateStr, timeStr) {
|
|
123
|
+
const mealType = getMealTypeByTime(timeStr);
|
|
124
|
+
if (!mealType) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const mealData = getDataByDateAndMealWithExceptions(data, dateStr, mealType);
|
|
128
|
+
if (!mealData) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const requestedTime = parseTime(timeStr);
|
|
133
|
+
const startTime = parseTime(mealData.startTime);
|
|
134
|
+
const endTime = parseTime(mealData.endTime);
|
|
135
|
+
|
|
136
|
+
const includeEndTime = shouldIncludeEndTime(mealType, mealData.endTime);
|
|
137
|
+
|
|
138
|
+
const timeFallsWithin =
|
|
139
|
+
includeEndTime
|
|
140
|
+
? requestedTime >= startTime && requestedTime <= endTime
|
|
141
|
+
: requestedTime >= startTime && requestedTime < endTime;
|
|
142
|
+
|
|
143
|
+
return timeFallsWithin ? mealData : null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
module.exports = {
|
|
147
|
+
getDataByDateAndMealWithExceptions,
|
|
148
|
+
getDataByDateAndTimeWithExceptions,
|
|
149
|
+
};
|
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
// index.js
|
|
2
|
-
|
|
3
|
-
const daysOfWeekEnglish = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
4
|
-
const daysOfWeekDutch = ['zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag'];
|
|
5
|
-
|
|
6
|
-
const shifts = {
|
|
7
|
-
breakfast: { start: '07:00', end: '11:00' },
|
|
8
|
-
lunch: { start: '11:00', end: '16:00' },
|
|
9
|
-
dinner: { start: '16:00', end: '23:00' },
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
function parseTime(timeStr) {
|
|
13
|
-
const [hours, minutes] = timeStr.split(':').map(Number);
|
|
14
|
-
return hours * 60 + minutes;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function getMealTypeByTime(timeStr) {
|
|
18
|
-
const time = parseTime(timeStr);
|
|
19
|
-
for (const [mealType, shift] of Object.entries(shifts)) {
|
|
20
|
-
const start = parseTime(shift.start);
|
|
21
|
-
const end = parseTime(shift.end);
|
|
22
|
-
if (time >= start && time < end) {
|
|
23
|
-
return mealType;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function getDataByDayAndMeal(data, dayOfWeek, mealType) {
|
|
30
|
-
const mealKey = `openinghours-${mealType}`;
|
|
31
|
-
if (!data[mealKey]) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
const mealData = data[mealKey];
|
|
35
|
-
const dayData = mealData.schemeSettings[dayOfWeek];
|
|
36
|
-
if (!dayData) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
return { ...dayData };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function adjustMealData(mealData, generalSettings) {
|
|
43
|
-
if (mealData.maxCapacityEnabled === false) {
|
|
44
|
-
if (generalSettings && generalSettings.zitplaatsen) {
|
|
45
|
-
mealData.maxCapacity = generalSettings.zitplaatsen;
|
|
46
|
-
mealData.maxCapacityEnabled = true;
|
|
47
|
-
} else {
|
|
48
|
-
mealData.maxCapacity = '0';
|
|
49
|
-
mealData.maxCapacityEnabled = true;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function getDuurReservatie(data) {
|
|
55
|
-
let duurReservatie = 120;
|
|
56
|
-
if (
|
|
57
|
-
data['general-settings'] &&
|
|
58
|
-
data['general-settings'].duurReservatie &&
|
|
59
|
-
parseInt(data['general-settings'].duurReservatie, 10) > 0
|
|
60
|
-
) {
|
|
61
|
-
duurReservatie = parseInt(data['general-settings'].duurReservatie, 10);
|
|
62
|
-
}
|
|
63
|
-
return duurReservatie;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function addDuurReservatieToEndTime(mealData, data) {
|
|
67
|
-
const duurReservatie = getDuurReservatie(data);
|
|
68
|
-
const endMinutes = parseTime(mealData.endTime);
|
|
69
|
-
const newEndMinutes = endMinutes + duurReservatie;
|
|
70
|
-
const hours = String(Math.floor(newEndMinutes / 60)).padStart(2, '0');
|
|
71
|
-
const minutes = String(newEndMinutes % 60).padStart(2, '0');
|
|
72
|
-
mealData.endTime = `${hours}:${minutes}`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function getDataByDateAndMeal(data, dateStr, mealType) {
|
|
76
|
-
const date = new Date(dateStr);
|
|
77
|
-
if (isNaN(date)) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
const dayOfWeekIndex = date.getDay();
|
|
81
|
-
const dayOfWeek = daysOfWeekEnglish[dayOfWeekIndex];
|
|
82
|
-
let mealData = getDataByDayAndMeal(data, dayOfWeek, mealType);
|
|
83
|
-
if (!mealData || mealData.enabled !== true) {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
adjustMealData(mealData, data['general-settings']);
|
|
88
|
-
|
|
89
|
-
// Add duurReservatie to endTime
|
|
90
|
-
addDuurReservatieToEndTime(mealData, data);
|
|
91
|
-
|
|
92
|
-
return mealData;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function getDataByDateAndTime(data, dateStr, timeStr) {
|
|
96
|
-
const mealType = getMealTypeByTime(timeStr);
|
|
97
|
-
if (!mealType) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
const mealData = getDataByDateAndMeal(data, dateStr, mealType);
|
|
101
|
-
if (!mealData) {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
const requestedTime = parseTime(timeStr);
|
|
105
|
-
const startTime = parseTime(mealData.startTime);
|
|
106
|
-
const endTime = parseTime(mealData.endTime);
|
|
107
|
-
if (requestedTime >= startTime && requestedTime < endTime) {
|
|
108
|
-
return mealData;
|
|
109
|
-
} else {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
module.exports = {
|
|
115
|
-
getDataByDayAndMeal,
|
|
116
|
-
getDataByDateAndMeal,
|
|
117
|
-
getDataByDateAndTime,
|
|
118
|
-
daysOfWeekEnglish,
|
|
119
|
-
daysOfWeekDutch,
|
|
120
|
-
getMealTypeByTime,
|
|
121
|
-
parseTime,
|
|
122
|
-
shifts,
|
|
123
|
-
};
|
|
1
|
+
// index.js
|
|
2
|
+
|
|
3
|
+
const daysOfWeekEnglish = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
4
|
+
const daysOfWeekDutch = ['zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag'];
|
|
5
|
+
|
|
6
|
+
const shifts = {
|
|
7
|
+
breakfast: { start: '07:00', end: '11:00' },
|
|
8
|
+
lunch: { start: '11:00', end: '16:00' },
|
|
9
|
+
dinner: { start: '16:00', end: '23:00' },
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function parseTime(timeStr) {
|
|
13
|
+
const [hours, minutes] = timeStr.split(':').map(Number);
|
|
14
|
+
return hours * 60 + minutes;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getMealTypeByTime(timeStr) {
|
|
18
|
+
const time = parseTime(timeStr);
|
|
19
|
+
for (const [mealType, shift] of Object.entries(shifts)) {
|
|
20
|
+
const start = parseTime(shift.start);
|
|
21
|
+
const end = parseTime(shift.end);
|
|
22
|
+
if (time >= start && time < end) {
|
|
23
|
+
return mealType;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getDataByDayAndMeal(data, dayOfWeek, mealType) {
|
|
30
|
+
const mealKey = `openinghours-${mealType}`;
|
|
31
|
+
if (!data[mealKey]) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const mealData = data[mealKey];
|
|
35
|
+
const dayData = mealData.schemeSettings[dayOfWeek];
|
|
36
|
+
if (!dayData) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return { ...dayData };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function adjustMealData(mealData, generalSettings) {
|
|
43
|
+
if (mealData.maxCapacityEnabled === false) {
|
|
44
|
+
if (generalSettings && generalSettings.zitplaatsen) {
|
|
45
|
+
mealData.maxCapacity = generalSettings.zitplaatsen;
|
|
46
|
+
mealData.maxCapacityEnabled = true;
|
|
47
|
+
} else {
|
|
48
|
+
mealData.maxCapacity = '0';
|
|
49
|
+
mealData.maxCapacityEnabled = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function getDuurReservatie(data) {
|
|
55
|
+
let duurReservatie = 120;
|
|
56
|
+
if (
|
|
57
|
+
data['general-settings'] &&
|
|
58
|
+
data['general-settings'].duurReservatie &&
|
|
59
|
+
parseInt(data['general-settings'].duurReservatie, 10) > 0
|
|
60
|
+
) {
|
|
61
|
+
duurReservatie = parseInt(data['general-settings'].duurReservatie, 10);
|
|
62
|
+
}
|
|
63
|
+
return duurReservatie;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function addDuurReservatieToEndTime(mealData, data) {
|
|
67
|
+
const duurReservatie = getDuurReservatie(data);
|
|
68
|
+
const endMinutes = parseTime(mealData.endTime);
|
|
69
|
+
const newEndMinutes = endMinutes + duurReservatie;
|
|
70
|
+
const hours = String(Math.floor(newEndMinutes / 60)).padStart(2, '0');
|
|
71
|
+
const minutes = String(newEndMinutes % 60).padStart(2, '0');
|
|
72
|
+
mealData.endTime = `${hours}:${minutes}`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function getDataByDateAndMeal(data, dateStr, mealType) {
|
|
76
|
+
const date = new Date(dateStr);
|
|
77
|
+
if (isNaN(date)) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const dayOfWeekIndex = date.getDay();
|
|
81
|
+
const dayOfWeek = daysOfWeekEnglish[dayOfWeekIndex];
|
|
82
|
+
let mealData = getDataByDayAndMeal(data, dayOfWeek, mealType);
|
|
83
|
+
if (!mealData || mealData.enabled !== true) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
adjustMealData(mealData, data['general-settings']);
|
|
88
|
+
|
|
89
|
+
// Add duurReservatie to endTime
|
|
90
|
+
addDuurReservatieToEndTime(mealData, data);
|
|
91
|
+
|
|
92
|
+
return mealData;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function getDataByDateAndTime(data, dateStr, timeStr) {
|
|
96
|
+
const mealType = getMealTypeByTime(timeStr);
|
|
97
|
+
if (!mealType) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const mealData = getDataByDateAndMeal(data, dateStr, mealType);
|
|
101
|
+
if (!mealData) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
const requestedTime = parseTime(timeStr);
|
|
105
|
+
const startTime = parseTime(mealData.startTime);
|
|
106
|
+
const endTime = parseTime(mealData.endTime);
|
|
107
|
+
if (requestedTime >= startTime && requestedTime < endTime) {
|
|
108
|
+
return mealData;
|
|
109
|
+
} else {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
module.exports = {
|
|
115
|
+
getDataByDayAndMeal,
|
|
116
|
+
getDataByDateAndMeal,
|
|
117
|
+
getDataByDateAndTime,
|
|
118
|
+
daysOfWeekEnglish,
|
|
119
|
+
daysOfWeekDutch,
|
|
120
|
+
getMealTypeByTime,
|
|
121
|
+
parseTime,
|
|
122
|
+
shifts,
|
|
123
|
+
};
|