I have an “availabilities” collection. Inside this collection could be a few entries that are date based for example:
{
"_id": "64b03ed794d87927a3066e13",
"startDateTime": "2023-07-07T18:00:00.000Z",
"endDateTime": "2023-07-12T15:00:00.000Z",
"availabilityType": "blackout"
}
{
"_id": "64b03eb094d87927a3066ddb",
"startDateTime": "2023-07-03T18:00:00.000Z",
"endDateTime": "2023-07-06T15:00:00.000Z",
"availabilityType": "blackout"
}
I am trying to figure out the best way to create an array of dates for the month and if there is an “availability” for some of the days, then return that within the date array. I thought about creating an array of days using javascript but then I’d have to iterate for each day to see there are any “availabilities” on the day; this seems very inefficient.
Ideally what I am looking to build is something similar to the following:
[
{
"date": "2023-07-01",
"availabilityType": "available"
},
{
"date": "2023-07-02",
"availabilityType": "available"
},
{
"date": "2023-07-03",
"availabilityType": "booked" // because there was an availability entry in the collection that is marked as booked
},
{
"date": "2023-07-04",
"availabilityType": "booked" // because there was an availability entry in the collection that is marked as booked
},
{
"date": "2023-07-05",
"availabilityType": "booked" // because there was an availability entry in the collection that is marked as booked
},
{
"date": "2023-07-06",
"availabilityType": "booked" // because there was an availability entry in the collection that is marked as booked
},
... etc up to July 31
]
Any suggestions on how this might be done?