mirror of
https://github.com/Fayorg/calendrier-avant.git
synced 2026-05-28 01:28:37 +02:00
Update grade route.ts to Next 13
This commit is contained in:
@@ -1,25 +1,23 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import {NextResponse} from "next/server";
|
||||
|
||||
import prisma from '@lib/prisma';
|
||||
|
||||
interface IBody {
|
||||
key: string
|
||||
grade: number
|
||||
}
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const body = req.body as IBody
|
||||
if (req.method === 'POST') {
|
||||
// Process a POST request
|
||||
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}})
|
||||
res.status(200).json({message: 'Grade updated', cookie: 'voted=true'})
|
||||
} else {
|
||||
res.status(404).json({message: 'Key not found'})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// Handle any other HTTP method
|
||||
}
|
||||
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 new NextResponse(
|
||||
JSON.stringify({message: 'Grade updated', cookie: 'voted=true'}), {status: 200}
|
||||
)
|
||||
} else {
|
||||
return new NextResponse(
|
||||
JSON.stringify({message: 'Key not found'}), {status: 404}
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user