diff --git a/app/api/grade/route.ts b/app/api/grade/route.ts new file mode 100644 index 0000000..12eb30a --- /dev/null +++ b/app/api/grade/route.ts @@ -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 + } +} diff --git a/package-lock.json b/package-lock.json index 9a73de8..0812eaa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "calendrier-avant", "version": "0.1.0", "dependencies": { + "@prisma/client": "^5.6.0", "next": "14.0.3", "prisma": "^5.6.0", "react": "^18", @@ -381,12 +382,37 @@ "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": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.6.0.tgz", "integrity": "sha512-Mt2q+GNJpU2vFn6kif24oRSBQv1KOkYaterQsi0k2/lA+dLvhRX6Lm26gon6PYHwUM8/h8KRgXIUMU0PCLB6bw==", "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": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/@rushstack/eslint-patch/-/eslint-patch-1.6.0.tgz", diff --git a/package.json b/package.json index 981731b..234a5b6 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "lint": "next lint" }, "dependencies": { + "@prisma/client": "^5.6.0", "next": "14.0.3", "prisma": "^5.6.0", "react": "^18", diff --git a/passwords.ts b/passwords.ts new file mode 100644 index 0000000..1fe3209 --- /dev/null +++ b/passwords.ts @@ -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) + }) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index eb5db00..81e36ad 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -7,3 +7,16 @@ datasource db { generator client { 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()) +}