This episode is for members only

Sign up to access "Build an Appointment Booking System With Inertia" right now.

Get started
Already a member? Sign in to continue
Playing
05. Employee schedules and exclusions

Episodes

0%
Your progress
  • Total: 5h 0m
  • Played: 0m
  • Remaining: 5h 0m
Join or sign in to track your progress

Transcript

00:00
OK, so we're going on to employee schedules now.
00:02
We'll define the schema out, talk a little bit more about these, and then, of course, we can start using them when we build this functionality up in the next episode.
00:11
OK, so let's start out by, again, creating out a model here. This is just going to be represented by a model. And we are going to call this schedule.
00:19
We can call these availabilities if we want to, but I think schedule is a little bit more appropriate. Again, we're going to generate a migration and a factory. So let's go over to the Create Schedules table migration.
00:31
And this is where things start to get annoying, because we're going to have to define all of them columns for the Monday, Tuesday, Wednesday, all the way up to Sunday.
00:38
Again, this is the easiest way to do this. We want this to be fast. We want this to work really nicely with an admin panel when we want to fill in these specific dates.
00:46
So we want this to be basically just, I want to insert these into this database table, and it just work. So let's get started on the first one.
00:54
This is, of course, going to be the employee that this relates to. So let's go ahead and add in a foreign ID for the employee ID,
01:01
and we'll go ahead and constrain this. And the next two are the general starts at and the general ends at date. So this could be like a year period.
01:10
So let's go ahead and define this out as a date in here. We're not going to set this as a date time, because the times come in very specifically later. And we'll say starts at,
01:19
and then we'll create another one in here. We'll set this to nullable just in case. It doesn't really matter too much. And we'll set ends at.
01:26
So that could be like from today, and then this could be like one year into the future. So we have a one year schedule. Now, after that comes the individuals.
01:37
So let's just do one, and then we're going to copy and paste them down and switch them over. These are going to be times.
01:42
So we've got the overall dates that we start, and these can be broken up into multiple chunks as well. Like you might have a six month period, and then have six months off,
01:51
and then have another six month period after that. And that's why this system is so flexible. So we're going to say Monday starts at, and we're going to make that nullable, of course,
02:01
because we might not work on Mondays. And we're going to say Monday ends at. So we're going to duplicate these down for every single day of the week.
02:09
I'm going to do that now. Of course, you can do that if you're following along. And then we'll have the fine grain control that we need for these employees schedules.
02:19
So let's go ahead and duplicate these down now. Okay, and we're done. We've got all of these in here now. Again, a little bit annoying,
02:25
but trust me, this is the easiest way to insert these in here and have really good control over them. Okay, so now that we've done this,
02:32
of course, let's go ahead and migrate this. And we'll go over to the schedule model, and we'll fill in a couple of bits in here in a minute. But first, let's go over to the database
02:42
just to add in a schedule. So I'm going to go ahead and add in one for myself. And I'm going to say that this starts at now, ends at now.
02:51
Then what we can do is go ahead and adjust this. So I'm just going to say, I want this to end one year into the future. So for Monday starts out again and Monday ends out,
03:02
we'll set these to now and then just adjust the date. So we'll say that we're going to start work on a Monday at nine, and we're going to finish at five o'clock.
03:11
And you can do that for every single one that you have in here. So we can go ahead and duplicate them across if we want to. I'm not going to do that
03:19
because our tests will make sure that this is working properly, but we'll just leave that as it is. But you'd want to fill these in
03:25
or have an admin panel that inserted in these dates for you. Okay, so the next thing we want to talk about is just the schedule model. We'll just build this up really, really roughly for now.
03:34
We want to go ahead and add in some casts in here. Now we're not going to cast the Monday starts at, Monday ends at stuff, but we are going to cast the overall starts at
03:44
and ends at dates, and we'll see why a little bit later. So I'm going to cast these starts at and the ends at to a date.
03:52
And then we're just going to fill in the relationship back to the employee. So let's add in an employee relationship here and just say this belongs to,
04:01
and of course, belongs to that employee here. Great. Okay, so that's pretty much it for our schedule. Let's go over to our employee model itself
04:11
and then add in these schedules. Remember, we can have multiple schedules as well. So let's go ahead and say schedules, and we're going to say that this has many,
04:23
and of course, define out that schedule in there so we can access the schedules for the employees and check within them. Okay, so really annoyingly over in our schedule factory,
04:33
we're going to have to fill in the Monday starts at, Monday ends at for all of these columns. When we test this, we can adjust these as we build these up,
04:43
but we want these to be in there. So it's just a nine to five for every day just to simplify our test. So to do this,
04:49
we're just going to go ahead and add in Monday starts at. I'm going to leave out the starts at and ends at because we're almost always going to include them manually within our tests.
04:59
But in here, we can just set 090000 and do the same for ends at and just set that to a default. And once again, I'm going to do this for every single day that we have,
05:12
and I'll be back with you. Okay, and we're done. So that means that when we do write our tests, we don't need to fill these in for every single day
05:19
within a period that we want to check for. Okay, so the next thing are the schedule exclusions. So we've built up when someone is working from until, the days and the times that they work.
05:29
Now we want to add in the exclusions and that might be something like a holiday that the user has. So let's go ahead and build this up again as a model.
05:38
And this is going to be a schedule exclusion. Again, we'll generate a migration and a factory alongside of this as well, though we don't really need a factory here
05:47
to define the data because we're going to be doing this manually within our tests. So let's go over to the schedule exclusions table. This is much simpler.
05:56
Of course, it needs to be for a specific employee. That's really important. But the starts at and ends at will be flexible. So we could say that we want this to start on Monday midday
06:10
and end on Friday midday. And they might work half of Friday. So we can make this as flexible as we want when we build up these periods that we're working with.
06:19
So we're just going to have a standard timestamp in here, not a date, not a specific time. And we're going to say starts at and we're going to have an ends at in here.
06:27
And that's pretty much all we need to do. So a little bit of context around this, when we start to build these periods up, we're going to use a package that allows us
06:35
to generate these periods and then slice them up. So if you think about it, we've created our schedule, which has a year period with all of them dates in, but then our starts at and ends at here
06:45
can just cut that period in the middle. And then we can look at availability either side of that. So that's pretty much how this is going to work when we get to building this system up.
06:54
Okay, so now that we've done that, let's go ahead and just migrate what we have here. And we're going to head over to our employee model. And I think I added, let's just have a look here.
07:03
Yeah, for some reason added the schedules into that factory, which is of course not right. You probably noticed that. So we've got the schedules
07:10
and now we just want to add in the schedule exclusions. So schedule exclusions, and it has many exclusions. And that's pretty much it. Now for the schedule itself, we added in these casts.
07:21
We're going to do the same thing for the schedule exclusion. Cause when we grab that out, we're going to want these to be carbon objects. So let's go over to our schedule exclusion model
07:31
and we'll just add these start and end as a date time. So when we extract them out, they will be carbon instances, which we can really easily work with. Okay, so that's pretty much it for our schedule
07:44
and our schedule exclusions. We might need to come back to tie up a few loose ends a little bit later, but that's pretty much what we need to add in there to get this working.
39 episodes5 hrs 0 mins

Overview

Building an availability calendar and booking system is a notoriously difficult problem to solve. That’s exactly what we’re going to cover in this course.

Step by step, we’ll build an appointment slot generator that calculates availability based on employee schedules, employee’s booked time off, the length of service chosen, existing appointments, and cancelled appointments.

For maximum flexibility, we’ll also allow multi-employee availability checks, so we’ll be able to see every employee who can perform a service (and their available slots).

To finish up, we’ll create an entire booking flow with Inertia (using Vue), including a beautiful booking calendar that shows detailed availability across multiple dates, the ability to choose a time slot — and finally the ability to book an appointment.

Phew. We’ve got a lot to learn — let’s build a booking system with Inertia!

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Episode discussion

No comments, yet. Be the first!