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:
27
app/api/grade/route.ts
Normal file
27
app/api/grade/route.ts
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user