Hey all,
I’m essentially trying to create an online course with dynamic pages (database name expData ) where users click a button to show they have completed a lesson. When they press the button, I get their userID, name, and what dynamic lesson page they’re on, and store it in a new database ( progressEXP ).
The code I have works, but when the user completes lessons on multiple pages, a new row is created in the database, even though the userID is the same.
What I want to happen is for there to be only one row per userID, so for this example this user would have one row with 4 items in the “status” column.
My code is below, any thoughts?
export function statusBtn1_onClick(event) {
$w('#statusBtn1').changeState("sectionComplete");
wixData.query("Members/PrivateMembersData")
.eq("_id", wixUsers.currentUser.id)
.find()
.then((results) => {
// get member info
let memberFirstName = results.items[0].firstName;
let memberLastName = results.items[0].lastName;
console.log(memberFirstName, memberLastName);
const user = wixUsers.currentUser;
const userId = user.id;
// get the dynamic page location
let currentItem = $w("#expData").getCurrentItem();
let section1Complete = [currentItem.title];
//what to save
let toSave = {
"memberID": userId,
"firstName": memberFirstName,
"lastName": memberLastName,
"status": section1Complete,
};
//store results in "progressEXP" database
wixData.save("progressEXP", toSave)
.then((results) => {
let item = results;
console.log("You did it");
})
.catch((err) => { let errorMsg = err;
});
})
}