diff --git a/chros/app/api/users/[userId]/route.ts b/chros/app/api/users/[userId]/route.ts new file mode 100644 index 0000000..4f51c8a --- /dev/null +++ b/chros/app/api/users/[userId]/route.ts @@ -0,0 +1,38 @@ +import { NextRequest, NextResponse } from "next/server"; +import { PrismaClient } from "@prisma/client"; + +const Prisma = new PrismaClient(); + +/** + * PATCH /api/users/[userId] + */ + +export async function PATCH( + request: NextRequest, + { params }: { params: { userId: string } }, +) { + try { + const { userId } = params; + const name = await request.json(); + if (!name || typeof name !== "string") { + return NextResponse.json({ error: "Name is required" }, { status: 400 }); + } + + const updatedUser = await Prisma.user.update({ + where: { + id: Number(userId), + }, + data: { + name, + }, + }); + + return NextResponse.json(updatedUser); + } catch (error) { + console.error(error); + return NextResponse.json( + { error: "Failed to update user" }, + { status: 500 }, + ); + } +} diff --git a/chros/app/api/users/route.ts b/chros/app/api/users/route.ts new file mode 100644 index 0000000..c1e74b6 --- /dev/null +++ b/chros/app/api/users/route.ts @@ -0,0 +1,49 @@ +import { NextResponse } from "next/server"; +import { PrismaClient } from "@prisma/client"; + +const prisma = new PrismaClient(); + +/** + * GET /api/users + */ + +export async function GET() { + try { + const users = await prisma.participant.findMany(); + return NextResponse.json(users); + } catch (error) { + console.error(error); + return NextResponse.json( + { error: "Failed to fetch users" }, + { status: 500 }, + ); + } +} + +/** + * POST /api/users + */ + +export async function POST(request: Request) { + try { + const { name } = await request.json(); + + if (!name || typeof name !== "string") { + return NextResponse.json({ error: "Name is required" }, { status: 400 }); + } + + const newUser = await prisma.participant.create({ + data: { + name, + }, + }); + + return NextResponse.json(newUser, { status: 201 }); + } catch (error) { + console.error(error); + return NextResponse.json( + { error: "Failed to create user" }, + { status: 500 }, + ); + } +} diff --git a/chros/package.json b/chros/package.json index 9ec636d..8ba3fb2 100644 --- a/chros/package.json +++ b/chros/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "dev": "next dev --turbopack", - "build": "next build --turbopack", + "build": "next build", "start": "next start" }, "dependencies": { diff --git a/chros/prisma/schema.prisma b/chros/prisma/schema.prisma index b889528..8aa17ae 100644 --- a/chros/prisma/schema.prisma +++ b/chros/prisma/schema.prisma @@ -77,4 +77,4 @@ model Score { @@unique([matchId, half]) @@index([coolId]) @@index([hotId]) -} \ No newline at end of file +} diff --git a/chros/tsconfig.json b/chros/tsconfig.json index d8b9323..1e2f493 100644 --- a/chros/tsconfig.json +++ b/chros/tsconfig.json @@ -5,6 +5,7 @@ "allowJs": true, "skipLibCheck": true, "strict": true, + "strictNullChecks": true, "noEmit": true, "esModuleInterop": true, "module": "esnext", diff --git a/docker-compose.yaml b/docker-compose.yaml index 037d02b..8feecbe 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,7 +1,7 @@ services: app: build: - context: ./webapp + context: ./chros dockerfile: Dockerfile ports: - "3000:3000" @@ -16,4 +16,4 @@ services: - POSTGRES_PASSWORD=password - POSTGRES_DB=database ports: - - "5432:5432" \ No newline at end of file + - "5432:5432"