@happychef/algorithm 1.0.1 → 1.0.2

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.
@@ -28,9 +28,10 @@ function parseDateTimeInTimeZone(dateStr, timeStr, timeZone) {
28
28
  * @param {string} dateStr - The date string in "YYYY-MM-DD" format.
29
29
  * @param {Array} reservations - An array of reservation objects.
30
30
  * @param {number} guests - The number of guests for the reservation.
31
+ * @param {Array} blockedSlots - Optional array of blocked time slots to exclude.
31
32
  * @returns {Object} - Returns a pruned object of available time blocks or shifts, or an empty object if out of range.
32
33
  */
33
- function getAvailableTimeblocks(data, dateStr, reservations, guests) {
34
+ function getAvailableTimeblocks(data, dateStr, reservations, guests, blockedSlots = []) {
34
35
  // Get 'uurOpVoorhand' from general settings
35
36
  let uurOpVoorhand = 4;
36
37
  if (
@@ -83,7 +84,7 @@ function getAvailableTimeblocks(data, dateStr, reservations, guests) {
83
84
  currentTimeInTimeZone.toDateString() === targetDateInTimeZone.toDateString();
84
85
 
85
86
  // Get available time blocks or shifts
86
- const availableTimeblocks = timeblocksAvailable(data, dateStr, reservations, guests);
87
+ const availableTimeblocks = timeblocksAvailable(data, dateStr, reservations, guests, blockedSlots);
87
88
 
88
89
  // If the date is today and uurOpVoorhand is greater than zero, prune time blocks
89
90
  if (isToday && uurOpVoorhand >= 0) {
@@ -57,16 +57,17 @@ function isDateWithinAllowedRange(data, dateStr) {
57
57
  * @param {string} dateStr - The date string in "YYYY-MM-DD" format.
58
58
  * @param {Array} reservations - An array of reservation objects.
59
59
  * @param {number} guests - The number of guests for the reservation.
60
+ * @param {Array} blockedSlots - Optional array of blocked time slots to exclude.
60
61
  * @returns {boolean} - Returns true if the date has at least one available timeblock, false otherwise.
61
62
  */
62
- function isDateAvailable(data, dateStr, reservations, guests) {
63
+ function isDateAvailable(data, dateStr, reservations, guests, blockedSlots = []) {
63
64
  // Check if date is within allowed range
64
65
  if (!isDateWithinAllowedRange(data, dateStr)) {
65
66
  return false;
66
67
  }
67
68
 
68
69
  // Get available timeblocks using the existing logic
69
- const availableTimeblocks = getAvailableTimeblocks(data, dateStr, reservations, guests);
70
+ const availableTimeblocks = getAvailableTimeblocks(data, dateStr, reservations, guests, blockedSlots);
70
71
 
71
72
  // Return true only if we have at least one available timeblock
72
73
  return Object.keys(availableTimeblocks).length > 0;
@@ -7,11 +7,12 @@ const { timeblocksAvailable } = require('./processing/timeblocksAvailable');
7
7
  * @param {string} timeStr - The time string in "HH:MM" format.
8
8
  * @param {Array} reservations - An array of existing reservation objects.
9
9
  * @param {number} guests - The number of guests for the new reservation request.
10
+ * @param {Array} blockedSlots - Optional array of blocked time slots to exclude.
10
11
  * @returns {boolean} - Returns true if the time is available, false otherwise.
11
12
  */
12
- function isTimeAvailable(data, dateStr, timeStr, reservations, guests) {
13
+ function isTimeAvailable(data, dateStr, timeStr, reservations, guests, blockedSlots = []) {
13
14
  // Get all available timeblocks for the specified date and guest count
14
- const availableTimeblocks = timeblocksAvailable(data, dateStr, reservations, guests);
15
+ const availableTimeblocks = timeblocksAvailable(data, dateStr, reservations, guests, blockedSlots);
15
16
 
16
17
  // Check if the specific timeStr is one of the available keys
17
18
  return Object.prototype.hasOwnProperty.call(availableTimeblocks, timeStr);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happychef/algorithm",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Restaurant and reservation algorithm utilities",
5
5
  "main": "index.js",
6
6
  "author": "happy chef",
@@ -58,7 +58,7 @@ function fitsWithinMeal(data, dateStr, startTimeStr, duurReservatie) {
58
58
  return startTime >= mealStartTime && startTime + duurReservatie <= mealEndTime;
59
59
  }
60
60
 
61
- function timeblocksAvailable(data, dateStr, reservations, guests) {
61
+ function timeblocksAvailable(data, dateStr, reservations, guests, blockedSlots = []) {
62
62
  const duurReservatie = getDuurReservatie(data);
63
63
  const intervalReservatie = getInterval(data);
64
64
 
@@ -112,6 +112,17 @@ function timeblocksAvailable(data, dateStr, reservations, guests) {
112
112
  }
113
113
  }
114
114
 
115
+ // Filter out blocked time slots
116
+ if (blockedSlots && blockedSlots.length > 0) {
117
+ for (const blockedSlot of blockedSlots) {
118
+ // Check if the blocked slot matches the current date
119
+ if (blockedSlot.date === dateStr && blockedSlot.time) {
120
+ // Remove the blocked time from available timeblocks
121
+ delete availableTimeblocks[blockedSlot.time];
122
+ }
123
+ }
124
+ }
125
+
115
126
  return availableTimeblocks;
116
127
  }
117
128