incridea-23 / incridea-server

Official Repository of Incridea'23 Backend!
https://incridea-test.onrender.com/graphql
12 stars 22 forks source link

Quiz portal: Finalize schema #21

Closed SrivatsaRUpadhya closed 7 months ago

SrivatsaRUpadhya commented 7 months ago

Make a quiz platform to conduct quizzes for first round of events

Requirements - Organizers [ ] Dashboard to create quiz [ ] View submissions and results [ ] Download results

- Participants [ ] Answer quiz [ ] View results

AnirudhKaranth commented 7 months ago

@swasthikshetty10 @SrivatsaRUpadhya

Rough schema

image

SrivatsaRUpadhya commented 7 months ago

Cool! But Could we have the options as string and the options are separated by commas. And we could have questions and quizzes as separate tables. Something like this:

model Quiz {
    id              String           @id @default(cuid())
    name            String
    description     String?
    Questions       Question[]
    QuizSubmissions QuizSubmission[]
    //Add branch and other event details for which the quiz is conducted
}

model Question {
    id         String  @id @default(cuid())
    quizId     String
    Quiz       Quiz    @relation(fields: [quizId], references: [id], onDelete: Cascade)
    question   String
    options    String //Options separated by comma
    image      String?
    answer     Int     @default(-1) //Index of the correct answer (0-based)
    userChoice Int?    @default(-1) //Index of the user answer (0-based)
    userId     Int?
    User       User?   @relation(fields: [userId], references: [id], onDelete: SetNull)

    @@index([quizId])
    @@index([userId])
}

model QuizSubmission {
    id        String   @id @default(cuid())
    userId    Int
    User      User     @relation(fields: [userId], references: [id], onDelete: Cascade)
    quizId    String
    Quiz      Quiz     @relation(fields: [quizId], references: [id], onDelete: Cascade)
    score     Int
    createdAt DateTime @default(now())

    @@index([userId])
    @@index([quizId])
}
AnirudhKaranth commented 7 months ago

Bro, what if we keep userchoice in separate table like Ex: Userchoice { id string PK questionId string FK userChoice Int? @default(-1) //Index of the user answer (0-based) userId Int? User User? } So that question details need not be repeated for each user.

SrivatsaRUpadhya commented 7 months ago

Sounds good

swasthikshetty10 commented 7 months ago

image

ahmedmsayeem commented 7 months ago

image

//Schemas for Quizzing enum QuestionType { MCQ FITB }

model Quiz { id String @id @default(cuid()) Round Round @relation(fields: [roundEventId, roundRoundNo], references: [eventId, roundNo]) name String description String startTime DateTime endTime DateTime Question Question[] roundEventId Int roundRoundNo Int

@@index([roundEventId, roundRoundNo]) }

model Question { id String @id question String image String? points Int @default(1) negativePoints Int @default(-1) type QuestionType Quiz Quiz @relation(fields: [quizId], references: [id],onDelete: Cascade) quizId String Options Options[] FITBAns FITBAns[]

@@index([quizId]) }

model Options { id String @id @default(cuid()) Question Question @relation(fields: [questionId], references: [id],onDelete: Cascade) questionId String value String isAnswer Boolean Answers Answers[]

@@index([questionId]) }

model Answers { Options Options @relation(fields: [optionId], references: [id],onDelete: Cascade) optionId String @id User User @relation(fields: [userId], references: [id],onDelete: Cascade) userId Int

@@index([optionId]) @@index([userId]) }

model FITBAns { id String @id @default(cuid()) value String User User @relation(fields: [userId], references: [id],onDelete: Cascade) userId Int Question Question @relation(fields: [questionId], references: [id],onDelete: Cascade) questionId String

@@index([userId]) @@index([questionId]) }

check this vro...lemme know the things to correct...specially the RoundID as foreign key in Quiz model...

satwikrprabhu commented 7 months ago

the schema is ready already, check the PR by Srivatsa