WSC-Nettie-Owners / wscnettie

https://www.wscnettie.com
2 stars 0 forks source link

Change How the Query in Quizzes Works #20

Open Nottommy11 opened 1 year ago

Nottommy11 commented 1 year ago

Currently, the query being used in the Quizzes page +page.svelte is getting the incorrect answers and the correct answers. The user can see this query in the Network tab in inspect mode. It should instead get the answers and then after the user submits, we will check for those questionid's in the net_correct_answers table and see if they are right.

Here is an example of what the query should look like after this change:

const myres = client.query({
    Method: 'POST',
    variables: {
        skip: skip,
        limit: limit
    },
    query: gql`
        query getNet${netLvl}Questions($limit: Int!, $skip: Int!) {
            net_${netLvl}_net_questions(limit: $limit, offset: $skip) {
                question
                questionid
                net_answers {
                    answer
                    answerid
                }
            }
        }
    `
});

return (await myres).data[`net_${netLvl}_net_questions`];

And then you will need a function that receives a questionid and answer and checks the net_correct_answers table. The query itself might look something like this: (Note: You could perhaps use a _in as well for this if you prefer to work with a list. Many different ways to tackle this, use what works for you)

const myres = client.query({
    Method: 'POST',
    variables: {
        questionid: questionid,
        answer: answer
    },
    query: gql`
            query CheckQuizQuestion($questionid: uuid!, $correctanswer: String!) {
                net_${netLvl}_net_correct_answers(where: {_and: [{questionid: {_eq: $questionid}}, {correctanswer: {_eq: $correctanswer}}]}) {
                    correctanswerid
                    correctanswer
                }
            }
    `
});

return (await myres).data[`net_${netLvl}_net_correct_answers`];

Then perhaps have a counter that tracks correct answers and keeps data for each question. This is the rough idea, feel free to do whatever works in your mind. We'll somehow want to get the correct answer as well to show them what was right.

Nottommy11 commented 1 year ago

IMPORTANT NOTE: You'll probably want Issue #10 to be completed before this so the queries are cleaned up a little bit.