In this episode, we dive into how to figure out which employees are available to work particular time slots. We start off by discussing two different approaches to matching employees with available slots—either looping through each slot and checking against employee availability, or looping through each employee's available periods and checking them against the slots. Either way is fine, since we're just checking all the data in the end.
From there, we pull out each employee's available periods using a custom ScheduleAvailability
class, making sure to also take into account which service the employee is working on (because not all employees can do all services). We then explore both the structure of our data and how we'll need to iterate over the dates and slots available, checking each time if a given employee can fill a given slot based on their availability.
Once we've got all our objects in place, we set things up so that if an employee's available period contains a particular slot time, then that employee gets added to the slot. We code up a custom method for adding employees to a slot—in essence, building a list of which employees are available for each time slot. Some quick testing shows it's working: empty slots for times no one can work, and populated slots where employees are available.
By the end of the episode, we've got a system where all the employees who can work each slot are correctly added in, and we can easily see and modify this data as needed. This sets us up nicely for whatever we want to do next, like assigning actual appointments or visualizing employee availability!