I currently manage two collections - events and bookings. https://i.sstatic.net/c9jAn.png
The Events collection contains various events, while the Bookings collection only includes the eventId of the event that needs to be booked and the user who is currently logged in.
To find events that have not been booked, I utilized lodash:
const results = _.differenceWith(
eventsArr,
bookingArr,
(event, booking) => event.id == booking.eventId
);
However, I am struggling to figure out how to select the events that have been booked. I tried filtering the events array based on the eventID from the other array, but it did not work as expected!
If anyone has any suggestions or ideas, they would be greatly appreciated!
EDIT: Including the data structure details here (thank you for the quick responses, providing a complete structure can assist others, especially since the backend is firebase).
The events array
{
"-LWSkZgZ-e84Aq7EnvOo" : {
"date" : "January 17",
"description" : "Lorem ipsum dolor amet fashion axe cray pour-over green juice...",
"imageUrl" : "https://images.pexels.com/photos/1047940/pexels-photo-1047940.jpeg?auto=compress&cs=tinysrgb&dpr=1&fit=crop&h=500&w=500",
"location" : {
"lat" : 77.88,
"lng" : 66.65,
"name" : "Texas CA"
},
"name" : "MetalBone",
"ticketsAvailable" : true
},
"-LWSkbMLqDlpTgcgFHy2" : {
"date" : "January 18",
"description" : "Mlkshk brooklyn gastropub paleo bicycle rights...",
"imageUrl" : "https://images.pexels.com/photos/849/people-festival-party-dancing.jpg?auto=compress&cs=tinysrgb&dpr=1&fit=crop&h=500&w=500",
"location" : {
"lat" : 32.77,
"lng" : 96.7,
"name" : "Dallas SF"
},
"name" : "Big Day Out",
"ticketsAvailable" : true
},
The bookings array
{
"-LWdae8S33xrHfLetvT7" : {
"eventId" : "-LWSkZgZ-e84Aq7EnvOo",
"userMail" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="95e1f0e6e1d5e1f0e6e1bbf6faf8">[email protected]</a>"
},
"-LWdj2UDTwVV6_71Bcyd" : {
"eventId" : "-LWTraS93uC37S21syqP",
"userMail" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bcc8d9cfc8fcc8d9cfc892dfd3d1">[email protected]</a>"
}
}