We have 5 databases to work from.
Bookings/Services
Bookings/Staff
Bookings/Schedule
Tutors
Courses
The Tutors DB shows all of the tutors. When clicking on a tutor, you’re shown all of courses that this tutor offers.
The course data is pulled from the Courses database.
When selecting a course from the tutors page, the viewer is led to the Bookings/Services servicepageUrl to allow for the standard Wix Bookings flow.
The only reason the Bookings/Schedule collection is being used is because I believe this is called through using “GetServiceAvailability” - however perhaps the collection itself does not need to be included? Within “GetServiceAvailability” there is a field key titled staffMemberId which shows the Bookings/Staff._id item values. When running GetServiceAvailability, the individual serviceId also comes through. (In reality, I think these are the only 2 keys that I really need to be “syncd”. I mainly just need the database to show that this serviceId is connected to this staffId.)
I need to be able to have all Bookings/Services data to update existing items, insert new items, and remove old items from and to the Courses database collection.
After this happens, I also need to have the Bookings/Staff data to update, insert, and remove old items when needed within both, the Courses database and the Tutors database.
Here is my main question: How do I do this while having all items updated to their collections Correctly? Right now I know how to randomly spurt out all of the data into the collections but, I do not know how to have the correct data applied to the correct items here in these collections.
Here is some code that I have been working with to try and test.
import wixData from 'wix-data';
import wixBookings from 'wix-bookings';
export function button1_click(event) {
console.log("Starting query")
wixData.query("Bookings/Services")
.find()
.then((results) => {
let items = results.items;
let item = items[0]
items.forEach((eachItem) => {
let eachId = eachItem._id
console.log(eachId)
wixBookings.getServiceAvailability(eachId)
.then((availability) => {
let slots = availability.slots;
let firstSlot = availability.slots[0];
let staffId = slots.staffMemberId;
slots.forEach((eachAvail) => {
let eachstaffId = eachAvail.staffMemberId
//wixData.insert("Courses", item)
console.log(eachstaffId)
//viewing slots instead will show arrays of data that include both the serviceId and the staffMemberId so naturally, these 2 items are connected. I need to take this data to send it to the correct fields within our courses and tutors database.
})
})
})
})
}
//wixData.insert("Courses", item)