1
0
mirror of https://github.com/Fayorg/calendrier-avant.git synced 2026-05-27 17:18:38 +02:00

add: auto-refresh on the results pages

This commit is contained in:
2023-12-18 16:17:29 +01:00
parent 8ca5133527
commit 25ec9c2e50
3 changed files with 81 additions and 49 deletions

33
actions/results.ts Normal file
View File

@@ -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 } } });
}