diff --git a/actions/grades.ts b/actions/grades.ts index dee4386..4d1f057 100644 --- a/actions/grades.ts +++ b/actions/grades.ts @@ -8,7 +8,6 @@ export async function getGrade(testId: number, userId: number) { grade: true, id: true, testId: true, - note: true, createdAt: true, }, where: { @@ -24,7 +23,6 @@ export async function addGrade(testId: number, userId: number, grade: number, no const newGrade = await prisma.grade.create({ data: { grade: grade, - note: note, testId: testId, userId: userId, } diff --git a/actions/mangeTest.ts b/actions/mangeTest.ts index 02a569c..ddc82db 100644 --- a/actions/mangeTest.ts +++ b/actions/mangeTest.ts @@ -16,7 +16,6 @@ export async function getActiveTest(date: Date) { select: { id: true, isActive: true, - isPassed: true, testOf: { select: { id: true, @@ -30,7 +29,6 @@ export async function getActiveTest(date: Date) { }, where: { isActive: true, - isPassed: false, testOn: new Date(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate().toString().length === 1 ? '0' + date.getDate() : date.getDate())), }, }); @@ -41,7 +39,6 @@ export async function getActiveTestWithGrade(date: Date, userId: number) { select: { id: true, isActive: true, - isPassed: true, testOf: { select: { id: true, @@ -54,7 +51,6 @@ export async function getActiveTestWithGrade(date: Date, userId: number) { select: { id: true, grade: true, - note: true, createdAt: true, }, take: 1, @@ -67,7 +63,6 @@ export async function getActiveTestWithGrade(date: Date, userId: number) { }, where: { isActive: true, - isPassed: false, testOn: new Date(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate().toString().length === 1 ? '0' + date.getDate() : date.getDate())), }, }); diff --git a/actions/results.ts b/actions/results.ts new file mode 100644 index 0000000..cd42c1d --- /dev/null +++ b/actions/results.ts @@ -0,0 +1,33 @@ +"use server"; +import prisma from "@/lib/prisma"; + +export interface Results { + name: string; + total: number; +} + +export async function getResults(testId: number) { + const grades = await prisma.grade.findMany({ where: { testId: testId, user: { isTeacher: false } } }); + + const allGrades = ['1', '1.5', '2', '2.5', '3', '3.5', '4', '4.5', '5', '5.5', '6']; + let gradeOccurences = new Array(allGrades.length).fill(0); + const gradeList = grades.map((grade) => grade.grade); + + for (let i = 0; i < gradeList.length; i++) { + gradeOccurences[allGrades.indexOf(gradeList[i].toString())]++; + } + + let data: Results[] = []; + for (let i = 0; i < gradeOccurences.length; i++) { + data.push({ + name: allGrades[i], + total: gradeOccurences[i], + }); + } + + return data; +} + +export async function getTeacherResult(testId: number) { + return await prisma.grade.findFirst({ where: { testId: testId, user: { isTeacher: true } } }); +} \ No newline at end of file diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx index e0b56e6..3ef202e 100644 --- a/app/dashboard/page.tsx +++ b/app/dashboard/page.tsx @@ -1,18 +1,16 @@ import prisma from '@/lib/prisma'; import ActiveCard from './ActiveCard'; import { getAuthServerSession } from '@/lib/authenticate'; -import { red } from 'next/dist/lib/picocolors'; import { redirect } from 'next/navigation'; export default async function Dashboard() { const authSession = await getAuthServerSession(); console.log(authSession); - if (!authSession || !authSession.user.isTeacher) return redirect('/'); + if (!authSession) return redirect('/'); - const tests = await prisma.test.findMany({ select: { isActive: true, isPassed: true, id: true, testOf: { select: { id: true, firstName: true, lastName: true, isTeacher: true } } } }); + const tests = await prisma.test.findMany({ select: { isActive: true, id: true, testOf: { select: { id: true, firstName: true, lastName: true, isTeacher: true } } } }); const activeTests = tests.filter((test) => test.isActive); - const passedTests = tests.filter((test) => test.isPassed); return (
Mme Tixhon :
-