diff --git a/app/api/grade/route.ts b/app/api/grade/route.ts index b2a05ed..667d120 100644 --- a/app/api/grade/route.ts +++ b/app/api/grade/route.ts @@ -8,15 +8,11 @@ interface IBody { export async function POST(req: Request){ const body = await req.json() as IBody - await prisma.grade.findFirst({where: {key: body.key}}).then(async (grade) => { - if (grade) { - await prisma.grade.create({data: {test: 1, grade: body.grade, key: body.key}}) - return NextResponse.json({message: 'Grade updated', cookie: 'voted=true'}, {status: 200}) - } else { - return NextResponse.json( - JSON.stringify({message: 'Key not found'}), {status: 404} - ) - } - }); + const grade = await prisma.grade.findFirst({ select: { id: true}, where: { oral: 1, key: { key: body.key } } }); + if(grade) return NextResponse.json({message: 'Deja vote'}, {status: 403}); + + const gradeCreated = await prisma.grade.create({ data: { key: { connect: { key: body.key } }, grade: body.grade, oral: 1 } }); + if(gradeCreated) return NextResponse.json({message: 'Vote enregistré'}, {status: 200}); + return NextResponse.json({message: 'Server error'}, {status: 500}) } diff --git a/app/layout.tsx b/app/layout.tsx index cc21aa1..6ab9985 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -3,11 +3,6 @@ import { Inter } from 'next/font/google'; const inter = Inter({ subsets: ['latin'] }); -export const metadata: Metadata = { - title: 'Create Next App', - description: 'Generated by create next app', -}; - export default function RootLayout({ children }: { children: React.ReactNode }) { return ( diff --git a/app/play/page.tsx b/app/play/page.tsx index 396c1c1..fef6c9f 100644 --- a/app/play/page.tsx +++ b/app/play/page.tsx @@ -22,9 +22,6 @@ export default function play() { const response = await fetch('/api/grade', { method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, body: JSON.stringify({ grade, key: password }), }); const data = await response.json(); diff --git a/app/results.tsx b/app/results.tsx deleted file mode 100644 index 55a1fde..0000000 --- a/app/results.tsx +++ /dev/null @@ -1,53 +0,0 @@ -"use server"; -import { - Chart as ChartJS, - CategoryScale, - LinearScale, - Tooltip, - PointElement, - LineElement, -} from "chart.js"; -import { Line } from "react-chartjs-2"; - -// Register ChartJS components using ChartJS.register -ChartJS.register( - CategoryScale, - LinearScale, - PointElement, - LineElement, - Tooltip -); - -import { PrismaClient } from '@prisma/client' - -const prisma = new PrismaClient() - -function getGrades() { - return prisma.grade.findMany() -} - - -const results = async () => { - const grades = await getGrades() - const gradesArray = grades.map(grade => grade.grade.toString()) - const allGrades = ["1", "1,5", "2", "2,5", "3", "3,5", "4", "4,5", "5", "5,5", "6"] - const gradesCount = allGrades.map(grade => gradesArray.filter(g => g === grade).length) - console.log(grades) - - return ( -
- -
- ); -}; -export default results; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index c09fb3d..a219fb4 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -16,7 +16,7 @@ model Keys { model Grade { id Int @id @default(autoincrement()) - test Int + oral Int grade Float key Keys @relation(fields: [keyId], references: [id]) keyId Int