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

Added grade route.ts

This commit is contained in:
timhaller
2023-12-04 10:06:18 +01:00
parent 7b96b489b3
commit 780a4ada45
5 changed files with 100 additions and 0 deletions

27
app/api/grade/route.ts Normal file
View File

@@ -0,0 +1,27 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
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'})
} else {
res.status(404).json({message: 'Key not found'})
}
})
} else {
// Handle any other HTTP method
}
}