Added grade route.ts
This commit is contained in:
parent
7b96b489b3
commit
780a4ada45
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
"name": "calendrier-avant",
|
"name": "calendrier-avant",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@prisma/client": "^5.6.0",
|
||||||
"next": "14.0.3",
|
"next": "14.0.3",
|
||||||
"prisma": "^5.6.0",
|
"prisma": "^5.6.0",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
|
@ -381,12 +382,37 @@
|
||||||
"node": ">= 8"
|
"node": ">= 8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@prisma/client": {
|
||||||
|
"version": "5.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.6.0.tgz",
|
||||||
|
"integrity": "sha512-mUDefQFa1wWqk4+JhKPYq8BdVoFk9NFMBXUI8jAkBfQTtgx8WPx02U2HB/XbAz3GSUJpeJOKJQtNvaAIDs6sug==",
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@prisma/engines-version": "5.6.0-32.e95e739751f42d8ca026f6b910f5a2dc5adeaeee"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16.13"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"prisma": "*"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"prisma": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@prisma/engines": {
|
"node_modules/@prisma/engines": {
|
||||||
"version": "5.6.0",
|
"version": "5.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.6.0.tgz",
|
||||||
"integrity": "sha512-Mt2q+GNJpU2vFn6kif24oRSBQv1KOkYaterQsi0k2/lA+dLvhRX6Lm26gon6PYHwUM8/h8KRgXIUMU0PCLB6bw==",
|
"integrity": "sha512-Mt2q+GNJpU2vFn6kif24oRSBQv1KOkYaterQsi0k2/lA+dLvhRX6Lm26gon6PYHwUM8/h8KRgXIUMU0PCLB6bw==",
|
||||||
"hasInstallScript": true
|
"hasInstallScript": true
|
||||||
},
|
},
|
||||||
|
"node_modules/@prisma/engines-version": {
|
||||||
|
"version": "5.6.0-32.e95e739751f42d8ca026f6b910f5a2dc5adeaeee",
|
||||||
|
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.6.0-32.e95e739751f42d8ca026f6b910f5a2dc5adeaeee.tgz",
|
||||||
|
"integrity": "sha512-UoFgbV1awGL/3wXuUK3GDaX2SolqczeeJ5b4FVec9tzeGbSWJboPSbT0psSrmgYAKiKnkOPFSLlH6+b+IyOwAw=="
|
||||||
|
},
|
||||||
"node_modules/@rushstack/eslint-patch": {
|
"node_modules/@rushstack/eslint-patch": {
|
||||||
"version": "1.6.0",
|
"version": "1.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/@rushstack/eslint-patch/-/eslint-patch-1.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rushstack/eslint-patch/-/eslint-patch-1.6.0.tgz",
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"lint": "next lint"
|
"lint": "next lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@prisma/client": "^5.6.0",
|
||||||
"next": "14.0.3",
|
"next": "14.0.3",
|
||||||
"prisma": "^5.6.0",
|
"prisma": "^5.6.0",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
import { PrismaClient } from '@prisma/client'
|
||||||
|
|
||||||
|
const prisma = new PrismaClient()
|
||||||
|
|
||||||
|
let users = 24
|
||||||
|
let keys = []
|
||||||
|
let keyLength = 8
|
||||||
|
let chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
// ... you will write your Prisma Client queries here
|
||||||
|
for (let i = 1; i <= users; i++) {
|
||||||
|
let key = ''
|
||||||
|
for (let j = 0; j < keyLength; j++) {
|
||||||
|
key += chars.charAt(Math.floor(Math.random() * chars.length))
|
||||||
|
}
|
||||||
|
await prisma.keys.create({
|
||||||
|
data: {
|
||||||
|
key: key
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
.then(async () => {
|
||||||
|
await prisma.$disconnect()
|
||||||
|
})
|
||||||
|
.catch(async (e) => {
|
||||||
|
console.error(e)
|
||||||
|
await prisma.$disconnect()
|
||||||
|
process.exit(1)
|
||||||
|
})
|
|
@ -7,3 +7,16 @@ datasource db {
|
||||||
generator client {
|
generator client {
|
||||||
provider = "prisma-client-js"
|
provider = "prisma-client-js"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model Keys {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
key String @unique
|
||||||
|
}
|
||||||
|
|
||||||
|
model Grade {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
test Int
|
||||||
|
grade Float
|
||||||
|
key String
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue