1
0
mirror of https://github.com/Fayorg/calendrier-avant.git synced 2026-05-28 01:28:37 +02:00

add: api routes

This commit is contained in:
2023-12-05 23:53:23 +01:00
parent 771c28fa32
commit fe914efa41
2 changed files with 92 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ import prisma from "@/lib/prisma";
export async function GET(req: NextRequest){
const date = req.nextUrl.searchParams.get("date");
const key = req.nextUrl.searchParams.get("key");
const test = await prisma.test.findFirst({
select: {
@@ -15,6 +16,18 @@ export async function GET(req: NextRequest){
lastName: true,
isTeacher: true
}
},
grades: {
select: {
note: true,
grade: true,
createdAt: true,
},
where: {
user: {
key: key || ""
}
}
}
},
where: {
@@ -33,6 +46,12 @@ export async function GET(req: NextRequest){
firstName: test.testOf.firstName,
lastName: test.testOf.lastName,
isTeacher: test.testOf.isTeacher
},
vote: {
hasVoted: test.grades?.length > 0,
grade: test.grades[0]?.grade,
note: test.grades[0]?.note,
createdAt: test.grades[0]?.createdAt
}
});
}