Hey everyone, so i’m creating a quiz system for my church for our children to see how much they’ve studied their bible. It’s going to display different set of questions each week From 1 database and it will accept a Username along with the answers and store it in another database upon submission.
The first database Called BibleStudies stores the user answers, username and should get the StudyCode from the second database called BibleStudiesInput that has the Questions and store it in the field “BibleCode”
Database 1
Database 2
I followed a guide on preventing duplicate submission for quizName.
// Programmer: Nabeel
import wixData from 'wix-data';
export function searchForDuplicatesUsernames( value) {
// info contains the hook context
// use the collectionName property to use function for multiple collections
return wixData.query("BibleStudies")
.eq("quizName", value.quizName)
.find()
.then((results) => {
return results.items.length;
})
.catch((err) => {
let errorMsg = err;
});
}
export function BibleStudies_beforeInsert(item, context)
{
return searchForDuplicatesUsernames(item, context).then((res) =>
{
if(res >0)
{
return Promise.reject("You've already submitted a quiz for this week.");
}
});
}
export function onUpDate(value) {
return wixData.query("BibleStudies")
.eq("quizName", value.quizName)
//.eq("bibleCode", value.bibleCode)
.find()
.then((results) => {
return results.items.length;
})
.catch((err) => {
let errorMsg = err;
})
}
my question is how can I prevent duplication of a user if BOTH username and BibleCode is already in the database…
Meaning they can only submit once per weekly quiz with a specific BibleCode
So if the BibleCode is different it will allow a new submission despite having the username for another quiz present.