Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions chros/app/api/users/[userId]/route.ts
Original file line number Diff line number Diff line change
@@ -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 },
);
}
}
49 changes: 49 additions & 0 deletions chros/app/api/users/route.ts
Original file line number Diff line number Diff line change
@@ -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 },
);
}
}
2 changes: 1 addition & 1 deletion chros/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"dev": "next dev --turbopack",
"build": "next build --turbopack",
"build": "next build",
"start": "next start"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion chros/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ model Score {
@@unique([matchId, half])
@@index([coolId])
@@index([hotId])
}
}
1 change: 1 addition & 0 deletions chros/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"strictNullChecks": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
app:
build:
context: ./webapp
context: ./chros
dockerfile: Dockerfile
ports:
- "3000:3000"
Expand All @@ -16,4 +16,4 @@ services:
- POSTGRES_PASSWORD=password
- POSTGRES_DB=database
ports:
- "5432:5432"
- "5432:5432"