How to Store New Bookings and Resolve Overlapping Bookings
In this lesson, we'll continue from the previous lesson and look to see how we can update the bookingsIndex of a listing document with the dates that have recently been booked by a tenant.
Get the project source code below, and follow along with the lesson material.
Download Project Source CodeTo set up the project on your local machine, please follow the directions provided in the README.md
file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.
This lesson preview is part of the TinyHouse: A Fullstack React Masterclass with TypeScript and GraphQL - Part Two course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.
Get unlimited access to TinyHouse: A Fullstack React Masterclass with TypeScript and GraphQL - Part Two, plus 70+ \newline books, guides and courses with the \newline Pro subscription.
In the last lesson, we got primarily almost everything within the create booking mutation resolver function complete except for preparing the resolve bookings index utility function. That will be responsible in producing a new bookings index object for the listing that's being booked. We could have this function set up in a different file, but we'll keep it in this file. So above and outside of our resolver's map, we'll construct the functions and the parameters it is to accept. It would accept a bookings index object and it would accept a check in date and check out date parameters of type string. And when resolved, it should return a map or an object that matched the type of the bookings index object being passed in. We'll need a type to specify the shape of the bookings index parameter. If we recall, the bookings index object will look something like this. We'll share this in the lesson manuscript and at the end of the day, the book ings index is our way for how we hope to handle dates and the booking of dates for listings. It's just an object that contains a set of nested objects with key value pairs. In the root level, the index will refer to the year the booking is made. Then the child of that will be the month the booking is made and then finally further down, the child will be the day in which at this moment, a true bullion will be applied for the days that have already been booked. The JavaScript function for getting a month starts at zero to represent January , which is why in this example here, zero references the month of January. So for this bookings index object, let's quickly talk about the dates that have already been booked. The first day of January 2019 has been booked. So the year would have the index of 2019, the month of zero would reference that of January and a one would reference the day. And that says true. So we booked this date or it's already been booked by someone else. And it's the same for the second day of the month. Once again, this is practically the same for all the months. So May 31, 2019, May would be 04 within the context of the JavaScript month and 31st year is true and so on. So let's assume that we have some new check in and check out dates for a booking that's just been made to this listing. Ass