diff --git a/Untitled Diagram.drawio b/Untitled Diagram.drawio new file mode 100644 index 0000000..bce32d0 --- /dev/null +++ b/Untitled Diagram.drawio @@ -0,0 +1 @@ +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 \ No newline at end of file diff --git a/components/Acc.jsx b/components/Acc.jsx index c3fd61a..3ba2826 100644 --- a/components/Acc.jsx +++ b/components/Acc.jsx @@ -6,8 +6,47 @@ import AccordionDetails from '@mui/material/AccordionDetails'; import Typography from '@mui/material/Typography'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import {Button} from '@mui/material'; +import { useTimer } from 'react-timer-hook'; +import { data } from 'autoprefixer'; + + + export default function Acc(props){ + const { + seconds, + minutes, + hours, + days, + isRunning, + start, + pause, + resume, + restart, + } = useTimer(props.timestamp); + + const emitter=(e)=>{ + (async () => { + const stamp=new Date(); + const rawResponse = await fetch('/api/set_answer', + { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + + body: JSON.stringify({ans:props.question.answer,timestamp:stamp.toUTCString(),time:15}) + } + ); + const content = await rawResponse.json(); + + console.log(content); + })(); + } + + + return(
@@ -16,13 +55,42 @@ export default function Acc(props){ aria-controls="panel1a-content" id="panel1a-header" > - Question {props.question.number} + Question {props.question.number} - - {props.question.question} + +
+
+
+ {seconds} +
+ +
+
+ + + {props.question.question} + + + - +
+ +
+ +
{props.question.options[0]}
+
{props.question.options[1]}
+
{props.question.options[2]}
+
{props.question.options[3]}
+ + +
+
+
diff --git a/components/Login.js b/components/Login.js index 017522d..ce499d3 100644 --- a/components/Login.js +++ b/components/Login.js @@ -11,6 +11,7 @@ import { useAuthState } from "react-firebase-hooks/auth"; function Login(){ const login_a=useAppContext() + const [login_status,setLoginstatus]=useState("Login to Start test Fast!") const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [user, loading, error] = useAuthState(auth); @@ -18,6 +19,26 @@ function Login(){ function loginHandler(){ signInWithGoogle(); } + function myloginHandler(){ + (async () => { + const rawResponse = await fetch('/api/validate_user', { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({email:email,opt:password}) + }); + const content = await rawResponse.json(); + if(content.result==="success") + {login_a.setEmail(email); + navigate.push("/nickname");} + else{ +setLoginstatus("Failed to login"); + } + console.log(content); + })(); +} useEffect(() => { if (loading) { console.log('Loading') @@ -33,8 +54,8 @@ login_a.setEmail(user.email);
Loading -
Login
-

Login to Start test Fast!

+
Login
+

{login_status}

- setPassword(e.target.value)} className='cursor-pointer outline outline-0 m-2 mx-4 bg-transparent' placeholder='Enter your password' />
-
- Remember me -
-
- -
+ +
-
+
- Loading
Continue with Google
-
Register
+
Loading diff --git a/components/Question.js b/components/Question.js index 8713572..5707e0a 100644 --- a/components/Question.js +++ b/components/Question.js @@ -11,15 +11,16 @@ function Questions(props) { const[selected,setSelected]=useState(-1); const [colors,setColors]=useState(["bg-white","bg-white","bg-white","bg-white"]); const [isOver,setOver]=useState(false); - const [button_color,setButtoncolor]=useState("green") - const [clickTime,setClicktime]=useState(15); + const [button_state,setButtonstate]=useState({color:"green",text:"submit"}) + const[question,setQuestion]=useState({count:"1" ,number:'1',question:'What the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}) + function MyTimer( {expiryTimestamp} ) { const { seconds, isRunning, } = useTimer({ expiryTimestamp, onExpire:() => { setOver(true); - setButtoncolor("green") + setButtonstate({color:"sky",text:"request question"}) }}); const handleClick=async (e)=>{ @@ -33,7 +34,7 @@ function Questions(props) { } const handleSubmit=async(e)=>{ setOver(true); - + if(button_state.color==="green"){ (async () => { const rawResponse = await fetch('/api/send_answer', { method: 'POST', @@ -47,7 +48,19 @@ function Questions(props) { console.log(content); })(); - setButtoncolor('purple') + setButtonstate({color:"purple",text:"submitted"})} + if(button_state.color==="sky"){ + (async () => { + const rawResponse = await fetch('/api/request_question', { }); + const content = await rawResponse.json(); + if(content.count==="0") return; + setButtonstate({color:"green",text:"submit"}); + setQuestion(content); + resetStates(); + console.log(content); + })(); + + } } // useEffect(()=>(console.log(selected)),[selected]) @@ -63,13 +76,13 @@ function Questions(props) {
-

{props.question.question}

+

{question.question}

- {props.question.options.map((option,id)=>{ + {question.options.map((option,id)=>{ return (
{option}
) })} -
Submit
+
{button_state.text}
diff --git a/pages/admin.js b/pages/admin.js index b3fe555..05893d0 100644 --- a/pages/admin.js +++ b/pages/admin.js @@ -2,57 +2,86 @@ import Accord from '../components/Accordination'; import {Paper,Input} from '@mui/material'; import Acc from '../components/Acc'; import { useEffect,useState } from 'react'; -import io from 'socket.io-client' -import { Timer } from '@mui/icons-material'; -let socket; + +const data=[ + {number:'1',question:"which is the world's biggest real estate company?",options:["L and T","McDonalds","Reliance","DLF"],ans:"McDonalds"}, + {number:'2',question:"which Indian movie has the highest worldwide collection?",options:["Dangal","3 Idiots","Bajrangi Bhaijaan","PK"],ans:"Dangal"}, + {number:'3',question:"Who was the first female president of India?",options:["Sushma Swaraj","Droupadi Murmu","Pratibha Patil","Sarojini Naidu"],ans:"Pratibha Patil"}, + {number:'4',question:"who is the golden investor of 2k22 hillfair?",options:["Unacademy","SJVNL","Dayal Sweets","Byjus"],ans:"Unacademy"}, + {number:'5',question:"'Nabha Sparsham Deeptam' is the motto of which military unit of india? ",options:["Coast Guard","Air Force","Air Force","Navy"],ans:"Air Force"}, + {number:'6',question:"what is the full form of GDP?",options:["Growth Domestic Price","Growth Daily Product","Gross Daily Product","Gross Domestic Product"],ans:"Gross Domestic Product"}, + {number:'7',question:"When is the ‘National Girl Child Day’ celebrated annually in India?",options:["21 March","14 November","24 January","5 December"],ans:"24 January"}, + {number:'8',question:"Who has been appointed new Prime Minister of United Kingdom?",options:["Boris Johnson","Rishi Sunak","Angela Merkel","Byjus"],ans:"Rishi Sunak"}, + {number:'9',question:"which company has the tag line of 'zindagi ke sath bhi zindagi ke baad bhi'?",options:["LIC","Bajaj Finance","SBI","HDFC"],ans:"LIC"}, + {number:'10',question:"What was the theme of Hill'fair 2022? ",options:["Mirage-Ocean of mystique","Ocean-Mirage of Pharoah","Pharaoh-Ocean of mystique","Mirage-oasis of mystique"],ans:"Mirage-oasis of mystique"}, + {number:'11',question:"The name 'PARAM' is an Indian Technology, what is it ?",options:["Supercomputer","Submarine","Rocket","Helicopter"],ans:"Supercomputer"}, + {number:'12',question:"which of these colours are not present in olympic rings?",options:["Red","Green","Blue","orange"],ans:"orange"}, + {number:'13',question:"Which stock market crash was biggest in the history?",options:["1994","1992","1991","1983"],ans:"1992"}, + {number:'14',question:"What is the full form of LCD?",options:["liquid crystal display","liquid crystal diode","lithium crystal diode","large crystal device"],ans:"liquid crystal display"}, + {number:'15',question:"Company with biggest market capitalization in India?",options:["Tata","Adani","Reliance","Unilever"],ans:"Reliance"}, + {number:'16',question:"When was E-Cell NIT Hamirpur formed? ",options:["2017","2018","2019","2008"],ans:"2018"}, + {number:'17',question:"which is the oldest stock exchange in asia? ",options:["bse","nse","cse(colombo)","cse(bejing)"],ans:"Supercomputer"}, + {number:'18',question:"What was the most-watched series on Netflix in 2019?",options:["Squid Games","stranger things","Never Have I ever","Breaking Bad"],ans:"stranger things"}, + {number:'19',question:"which brand of tata group is indulged in jewellery related business ?",options:["kalyan ","PC Jewelers ","tanishq","BlueStone"],ans:"tanishq"}, + {number:'20',question:"Latest Indian Unicorn>?",options:["Molbio Diagnostics","OneCard","Shiprocket","Helicopter"],ans:"Molbio Diagnostics"}, + + +] + export default function Home(){ const [timer,setTimer]=useState(15); useEffect(() => { - socketInitializer(); + return () => { console.log("This will be logged on unmount"); } }) -const socketInitializer = async () => { - await fetch('/api/socket'); - socket = io() - - socket.on('connect', () => { - console.log('connected') - }) - - -} const handleUpdate=(e)=>{ setTimer(e.target.value) } - +const [Questions,setQuestions]=useState([ + {number:'1',question:'What the fastest train in the India and what is its maximum speed or operating speed?', + options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}, {number:'2',question:'hat the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}, + {number:'3',question:'at the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}]); const emitter=(e)=>{ - console.log(e); - const time = new Date(); - time.setSeconds(time.getSeconds() + parseInt(timer)); - e.time=time - e.colors=["bg-white","bg-white","bg-white","bg-white"] - socket.emit('input-change',JSON.stringify( e)); + (async () => { + const rawResponse = await fetch('/api/update_question_state', + { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({state:""}) + } + ); + const content = await rawResponse.json(); + + console.log(content); + })(); } +// useEffect(()=>{ +// (async () => { +// const rawResponse = await fetch('/api/showq' ); +// const content = await rawResponse.json(); +// setQuestions(content); +// //console.log(content); +// })(); +// }) - const questions=[ - {number:'1',question:'What the fastest train in the India and what is its maximum speed or operating speed?', - options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}, +const time = new Date(); + time.setSeconds(time.getSeconds() + 300); - - {number:'2',question:'hat the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}, - {number:'3',question:'at the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']} - ] + const questions=data return ( {questions.map((data,id)=>{ - return () + return () })} {timer} diff --git a/pages/api/addq.js b/pages/api/addq.js index be855c8..7682bfc 100644 --- a/pages/api/addq.js +++ b/pages/api/addq.js @@ -4,17 +4,15 @@ const prisma = new PrismaClient() export default async function handler (req, res){ const {body}=req; - const user = await prisma.question.create( + const user = await prisma.questions.create( { data:{ question:body.question, number:body.number, + state:"inactive", + time:"", option:{ - create:{ - data:[ - ...body.option - ] - } + create:body.options } } }); diff --git a/pages/api/create_users.js b/pages/api/create_users.js new file mode 100644 index 0000000..e5eb7e2 --- /dev/null +++ b/pages/api/create_users.js @@ -0,0 +1,13 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +export default async function handler (req, res){ + const {body}=req; + body.data.map(async (data)=>{ + const user=await prisma.user.create({ + data:data + }); + }) +res.status(200).json({result:"success"}); +} \ No newline at end of file diff --git a/pages/api/request_question.js b/pages/api/request_question.js new file mode 100644 index 0000000..68e47a2 --- /dev/null +++ b/pages/api/request_question.js @@ -0,0 +1,15 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +export default async function handler (req, res){ + const {body}=req; + res.status() + const user = await prisma.question.findUnique( + { + where:{ + state:"active" + } + }); + res.status(200).json(user) +} \ No newline at end of file diff --git a/pages/api/send_reply.js b/pages/api/send_reply.js new file mode 100644 index 0000000..1409355 --- /dev/null +++ b/pages/api/send_reply.js @@ -0,0 +1,11 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +export default async function handler (req, res){ + const answer = await prisma.answer.findOne( + {where:{ + id:1 + }}); + +} \ No newline at end of file diff --git a/pages/api/set_answer.js b/pages/api/set_answer.js new file mode 100644 index 0000000..e91ce89 --- /dev/null +++ b/pages/api/set_answer.js @@ -0,0 +1,21 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +export default async function handler (req, res){ + const {body}=req.body; + body.a="hello"; + console.log(body.timestamp); + const usersWithPosts = await prisma.answer.update( + + {where:{id:1}, + + data:{ + "ans":body.ans, + "time":body.time, + "timestamp":body.timestamp + } +}); +res.status(200).json(body); + +} \ No newline at end of file diff --git a/pages/api/update_question_state.js b/pages/api/update_question_state.js new file mode 100644 index 0000000..0222aa4 --- /dev/null +++ b/pages/api/update_question_state.js @@ -0,0 +1,20 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +export default async function handler (req, res){ + const {body}=req; + + + const user = await prisma.question.update( + { + where:{ + number:req.number + }, + data:{ + state:body.state, + time:body.time + } + }); + res.status(200).json(user) +} \ No newline at end of file diff --git a/pages/api/validate_user.js b/pages/api/validate_user.js new file mode 100644 index 0000000..f33b2cd --- /dev/null +++ b/pages/api/validate_user.js @@ -0,0 +1,35 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +export default async function handler (req, res){ + const {body}=req; + let user; + try { + // body of try + user = await prisma.user.findUniqueOrThrow( + { + where:{ + email:body.email + }, + + }); + console.log(body) + console.log(user); +} +catch(error) { + res.status(200).json({result:"failed"});return; +} + + + + if(user===null){ + res.status(200).json({result:"failed"}); + return; + } + else if(user.opt === body.opt) + { res.status(200).json({result:"success"}); return;} + else + {user.result="failed"; + res.status(200).json(user);} +} \ No newline at end of file diff --git a/pages/nickname.js b/pages/nickname.js index 22cc980..6ee28a2 100644 --- a/pages/nickname.js +++ b/pages/nickname.js @@ -30,7 +30,7 @@ function Nickname(){ console.log(content); })(); console.log(login_a.email); - navigator.push('/quiz'); + navigator.push('/reply'); } function changeHandler(event){ diff --git a/pages/quiz.js b/pages/quiz.js index 49332fd..17ef2b6 100644 --- a/pages/quiz.js +++ b/pages/quiz.js @@ -7,29 +7,13 @@ function Quiz(){ const [input, setInput] = useState('') const [Question,setQuestion]=useState({number:'1',question:'What the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']}); useEffect(() => { - socketInitializer(); + return () => { console.log("This will be logged on unmount"); } }) -const socketInitializer = async () => { - await fetch('/api/socket'); - socket = io({"rejectUnauthorized" : false}) - - socket.on('connect', () => { - console.log('connected') - }) - socket.on('update-input', msg => { - setInput(msg) - setQuestion(JSON.parse(msg)); - }) -} -const onChangeHandler = (e) => { - setInput(e.target.value) - socket.emit('input-change', e.target.value) -} //const nickname=localStorage.getItem('nick') //const email=localStorage.getItem('email') //let Question = {number:'1',question:'What the fastest train in the India and what is its maximum speed or operating speed?',options:['Vande Bharat,130','Rajdhani Express ,120','Duranto Express,130','Bulllet Train,230']} diff --git a/pages/reply.js b/pages/reply.js new file mode 100644 index 0000000..9029357 --- /dev/null +++ b/pages/reply.js @@ -0,0 +1,132 @@ +import { useEffect, useState } from "react"; + +import {useAppContext} from '../context/notes/state' + + //const time = new Date(); + //time.setSeconds(time.getSeconds() + 5); + + +function Questions(props) { + const login_a=useAppContext(); + const[selected,setSelected]=useState(-1); + const [colors,setColors]=useState(["bg-green","bg-red","bg-purple","bg-yellow"]); + + const [button_state,setButtonstate]=useState({color:"green",text:"submit"}) + + + const handleSubmit=async(e)=>{ + + if(button_state.color==="green"){ + (async () => { + const rawResponse = await fetch('/api/send_answer', { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({number:props.question.number,select:selected,time:seconds, user:login_a.nick ,email:login_a.email}) + }); + const content = await rawResponse.json(); + + console.log(content); + })(); + setButtonstate({color:"purple",text:"submitted! Answer again "}) + } + if(button_state.color==="purple"){ + setButtonstate({color:"green",text:"submit"}); + (async () => { + const rawResponse = await fetch('/api/request_question', { }); + const content = await rawResponse.json(); + if(content.count==="0") return; + + setQuestion(content); + resetStates(); + console.log(content); + }); + + } + } + + // useEffect(()=>(console.log(selected)),[selected]) + + + const handleClick=async (e)=>{ + + setColors((colors)=>{if(selected===-1) return colors; colors[selected]="bg-white";colors[e.target.id]="bg-amber-300"; + return colors; + }) + setSelected(e.target.id); + + //console.log(e.target.sid,colors) + } + + + const resetStates=()=>{ + setColors(["bg-white","bg-white","bg-white","bg-white"]) + setSelected(-1) + + } + + useEffect(()=>{ + console.log("question updated") + resetStates(); + },[props.question]); + + return ( +
+ +
+
+
+
+
+ + +
+
+
+ +
+ +
a
+
b
+
c
+
d
+ + +
{button_state.text}
+
+
+
+
+) + } +export default Questions; + + +// useEffect(()=>{ +// if(isOver){ +// (async () => { +// const rawResponse = await fetch('/api/send_answer', { +// method: 'POST', +// headers: { +// 'Accept': 'application/json', +// 'Content-Type': 'application/json' +// }, +// body: JSON.stringify({number:props.question.number,user:props.user,selection:selected}) +// }); +// const content = await rawResponse.json(); +// // const answer=await content.answer; +// // ( (colors)=>{ +// // if(selected!=-1) +// // colors[selected]="bg-red-400" +// // colors[answer]="bg-green-400" +// // setColors(colors) +// // })(colors); + + +// //console.log(content); +// })(colors); + +// } +// },[isOver,colors,selected,props.question.number,props.user]) diff --git a/prisma/dev.db b/prisma/dev.db index 313602a..765f79d 100644 Binary files a/prisma/dev.db and b/prisma/dev.db differ diff --git a/prisma/migrations/20221125062420_changed_schme/migration.sql b/prisma/migrations/20221125062420_changed_schme/migration.sql new file mode 100644 index 0000000..2063a85 --- /dev/null +++ b/prisma/migrations/20221125062420_changed_schme/migration.sql @@ -0,0 +1,16 @@ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Questions" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "number" INTEGER NOT NULL, + "question" TEXT NOT NULL, + "state" TEXT NOT NULL DEFAULT 'inactive', + "time" TEXT NOT NULL DEFAULT '' +); +INSERT INTO "new_Questions" ("id", "number", "question") SELECT "id", "number", "question" FROM "Questions"; +DROP TABLE "Questions"; +ALTER TABLE "new_Questions" RENAME TO "Questions"; +CREATE UNIQUE INDEX "Questions_number_key" ON "Questions"("number"); +CREATE UNIQUE INDEX "Questions_question_key" ON "Questions"("question"); +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/20221125073529_user/migration.sql b/prisma/migrations/20221125073529_user/migration.sql new file mode 100644 index 0000000..c5ffd6a --- /dev/null +++ b/prisma/migrations/20221125073529_user/migration.sql @@ -0,0 +1,22 @@ +-- CreateTable +CREATE TABLE "Answer" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "ans" TEXT NOT NULL, + "time" TEXT NOT NULL +); + +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_User" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "email" TEXT NOT NULL, + "opt" TEXT NOT NULL DEFAULT '007', + "name" TEXT, + "score" INTEGER NOT NULL DEFAULT 0 +); +INSERT INTO "new_User" ("email", "id", "name", "score") SELECT "email", "id", "name", "score" FROM "User"; +DROP TABLE "User"; +ALTER TABLE "new_User" RENAME TO "User"; +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/20221125084728_add/migration.sql b/prisma/migrations/20221125084728_add/migration.sql new file mode 100644 index 0000000..dc9e999 --- /dev/null +++ b/prisma/migrations/20221125084728_add/migration.sql @@ -0,0 +1,19 @@ +/* + Warnings: + + - You are about to alter the column `time` on the `Answer` table. The data in that column could be lost. The data in that column will be cast from `String` to `Int`. + +*/ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Answer" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "ans" TEXT NOT NULL DEFAULT 'a', + "time" INTEGER NOT NULL DEFAULT 15, + "timestamp" TEXT +); +INSERT INTO "new_Answer" ("ans", "id", "time") SELECT "ans", "id", "time" FROM "Answer"; +DROP TABLE "Answer"; +ALTER TABLE "new_Answer" RENAME TO "Answer"; +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/20221125095151_number_add/migration.sql b/prisma/migrations/20221125095151_number_add/migration.sql new file mode 100644 index 0000000..5b90095 --- /dev/null +++ b/prisma/migrations/20221125095151_number_add/migration.sql @@ -0,0 +1,14 @@ +-- AlterTable +ALTER TABLE "Questions" ADD COLUMN "answer" TEXT; + +-- CreateTable +CREATE TABLE "Answer1" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "number" INTEGER NOT NULL, + "ans" TEXT NOT NULL DEFAULT 'a', + "time" INTEGER NOT NULL DEFAULT 15, + "timestamp" TEXT +); + +-- CreateIndex +CREATE UNIQUE INDEX "Answer1_number_key" ON "Answer1"("number"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 9c9aac6..1a33238 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -13,9 +13,26 @@ datasource db { model User { id Int @id @default(autoincrement()) email String @unique + opt String @default("007") name String? score Int @default(0) } +model Answer1{ +id Int @id @default(autoincrement()) +number Int @unique +ans String @default("a") +time Int @default(15) +timestamp String? + +} + +model Answer{ +id Int @id @default(autoincrement()) +ans String @default("a") +time Int @default(15) +timestamp String? + +} model Answers { id Int @id @default(autoincrement()) @@ -25,9 +42,12 @@ model Answers { model Questions { id Int @id @default(autoincrement()) - number Int @unique + number Int @unique question String @unique + state String @default("inactive") + time String @default("") option Option[] + answer String? } model Option {