API authentifiée

This commit is contained in:
2024-12-07 13:06:15 +01:00
parent 376c297eda
commit 45a1cebcf9
23 changed files with 783 additions and 41 deletions

View File

@ -5,6 +5,7 @@ CREATE TYPE "MoneyUpdateType" AS ENUM ('START', 'WIN_CHALLENGE', 'BUY_TRAIN');
CREATE TABLE "User" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"password" TEXT NOT NULL,
"money" INTEGER NOT NULL DEFAULT 0,
"currentRunner" BOOLEAN NOT NULL DEFAULT false,

View File

@ -10,6 +10,7 @@ datasource db {
model User {
id Int @id @default(autoincrement())
name String @unique
password String
money Int @default(0)
currentRunner Boolean @default(false)
actions ChallengeAction[]

View File

@ -1,17 +1,21 @@
import { PrismaClient } from '@prisma/client'
import * as bcrypt from 'bcrypt'
const prisma = new PrismaClient()
async function main() {
const emmyPassword = await bcrypt.hash("Emmy", 10)
const emmy = await prisma.user.upsert({
where: { id: 1 },
update: { name: 'Emmy' },
create: { name: 'Emmy' },
create: { name: 'Emmy', password: emmyPassword },
})
const taminaPassword = await bcrypt.hash("Tamina", 10)
const tamina = await prisma.user.upsert({
where: { id: 2 },
update: { name: 'Tamina' },
create: { name: 'Tamina' },
create: { name: 'Tamina', password: taminaPassword },
})
console.log({ emmy, tamina })
}