Sometimes, you just want to put in a date, and within milliseconds, be able to query a database filled with thousands of service providers to see who has an opening for the next 7 days because phone calls are major (and time-consuming!) sources of anxiety (just a little thing I made for fun trying to replicate real-world conditions as closely as I could).
Assumptions:
-
Providers enter their opening hours and booked hours.
-
This leads to two types of events in the DB - "openings" and "appointments"
-
The number of hours marked available (openings) on any given day is not previously known.
-
This means that openings can be of any length of hours, for example,
9:30am-6:00pm
or9:00am-11:30am
. -
Providers also update the system with appointments, or blocks of time they aren't available. These are 30-minute blocks, for example,
9:30am-10:00am
. -
The goal is to return openings (essentially potential appointments) of 30-minute blocks in a full workday that may have 0 or more appointments already scattered throughout it.
-
The data in the database will consist of "opening" and "appointment" events in a random order of days and hours, but returned data should be sorted in ascending order by days and hours.
-
Providers can also submit openings that they have on a weekly basis. These are marked as "weekly_recurring" which means that they only exist once in the database but the algorithm is expected to account for these openings reoccurring every seven days when displaying results to appointment bookers.
-
The returned data should list openings for a given day, in chronological order, for the next 7 days.
-
The query should be optimized for performance and work well on large datasets.
npm install
npm test --watchAll
or just go into src and look at the code