fix: api route

This commit is contained in:
Elie Baier 2023-12-04 10:49:46 +01:00
parent 4e7efb327f
commit e844983b41
1 changed files with 4 additions and 5 deletions

View File

@ -11,13 +11,12 @@ export async function POST(req: Request){
await prisma.grade.findFirst({where: {key: body.key}}).then(async (grade) => { await prisma.grade.findFirst({where: {key: body.key}}).then(async (grade) => {
if (grade) { if (grade) {
await prisma.grade.create({data: {test: 1, grade: body.grade, key: body.key}}) await prisma.grade.create({data: {test: 1, grade: body.grade, key: body.key}})
return new NextResponse( return NextResponse.json({message: 'Grade updated', cookie: 'voted=true'}, {status: 200})
JSON.stringify({message: 'Grade updated', cookie: 'voted=true'}), {status: 200}
)
} else { } else {
return new NextResponse( return NextResponse.json(
JSON.stringify({message: 'Key not found'}), {status: 404} JSON.stringify({message: 'Key not found'}), {status: 404}
) )
} }
}) });
return NextResponse.json({message: 'Server error'}, {status: 500})
} }