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

add: full authentication with NextAuth

This commit is contained in:
2023-12-18 14:59:34 +01:00
parent c48f1e23a3
commit 226100f25a
12 changed files with 273 additions and 130 deletions

34
actions/grades.ts Normal file
View File

@@ -0,0 +1,34 @@
"use server";
import prisma from "@/lib/prisma";
export async function getGrade(testId: number, userId: number) {
const grade = await prisma.grade.findFirst({
select: {
grade: true,
id: true,
testId: true,
note: true,
createdAt: true,
},
where: {
testId: testId,
userId: userId
}
});
return grade;
}
export async function addGrade(testId: number, userId: number, grade: number, note: string | null) {
const newGrade = await prisma.grade.create({
data: {
grade: grade,
note: note,
testId: testId,
userId: userId,
}
});
return newGrade;
}

View File

@@ -9,4 +9,66 @@ export async function setTestActive(id: number, active: boolean) {
return true;
}
export async function getActiveTest(date: Date) {
return await prisma.test.findFirst({
select: {
id: true,
isActive: true,
isPassed: true,
testOf: {
select: {
id: true,
firstName: true,
lastName: true,
isTeacher: true,
},
},
createdAt: true,
testOn: true,
},
where: {
isActive: true,
isPassed: false,
testOn: new Date(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate().toString().length === 1 ? '0' + date.getDate() : date.getDate())),
},
});
}
export async function getActiveTestWithGrade(date: Date, userId: number) {
return await prisma.test.findFirst({
select: {
id: true,
isActive: true,
isPassed: true,
testOf: {
select: {
id: true,
firstName: true,
lastName: true,
isTeacher: true,
},
},
grades: {
select: {
id: true,
grade: true,
note: true,
createdAt: true,
},
take: 1,
where: {
userId: userId
}
},
createdAt: true,
testOn: true,
},
where: {
isActive: true,
isPassed: false,
testOn: new Date(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate().toString().length === 1 ? '0' + date.getDate() : date.getDate())),
},
});
}