Little help with a quiz system

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.

Have a look at these previous forum posts.
https://www.wix.com/corvid/forum/community-discussion/code-to-allow-user-account-to-fill-a-form-just-one-time
https://www.wix.com/corvid/forum/community-discussion/how-to-limit-submissions-per-user

1 Like

Okay I will check them out…

@dreanofilms And perhaps a little prayer will help. :relieved:

3 Likes

Check out the link here too from @anastasiias (Wix Mod) in this other forum post too about limiting replies.
https://www.wix.com/corvid/forum/community-discussion/limit-number-of-form-submissions-to-1-per-member

2 Likes

@yisrael-wix
Although I don’t think that the Lord will write the code for them here, if he does then I’m taking a laptop to the next Sunday Service :innocent:

1 Like

Hi, Rated Luxury.

I don’t know if your code is actually left-justified as shown above; if it is, I recommend indentation (specifically, 2 spaces) within each block as follows:

// 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;
  })
}

That indentation can help with reading and understanding your code and seeing the flow more clearly.

2 Likes