1
0
mirror of https://github.com/Fayorg/calendrier-avant.git synced 2026-05-28 01:28:37 +02:00
This commit is contained in:
2023-12-04 11:37:10 +01:00
parent cc2dc0aa74
commit 873ff3d5ae
5 changed files with 7 additions and 72 deletions

View File

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