Type fixes & Docker

This commit is contained in:
headlessdev
2025-04-13 21:10:17 +02:00
parent dcce66a449
commit eadaf75b74
76 changed files with 21644 additions and 264 deletions

View File

@@ -1,53 +1,49 @@
import { NextResponse, NextRequest } from "next/server";
import { PrismaClient } from '@/lib/generated/prisma'
import { prisma } from "@/lib/prisma";
interface GetRequest {
page: number;
ITEMS_PER_PAGE: number;
interface PostRequest {
page?: number;
ITEMS_PER_PAGE?: number;
}
const prisma = new PrismaClient();
export async function POST(request: NextRequest) {
try {
const body: GetRequest = await request.json();
const page = Math.max(1, body.page || 1);
const ITEMS_PER_PAGE = body.ITEMS_PER_PAGE;
const applications = await prisma.application.findMany({
skip: (page - 1) * ITEMS_PER_PAGE,
take: ITEMS_PER_PAGE,
orderBy: { name: 'asc' }
});
try {
const body: PostRequest = await request.json();
const page = Math.max(1, body.page || 1);
const ITEMS_PER_PAGE = body.ITEMS_PER_PAGE || 10;
const serverIds = applications
.map(app => app.serverId)
.filter((id): id is number => id !== null);
const [applications, totalCount, servers_all] = await Promise.all([
prisma.application.findMany({
skip: (page - 1) * ITEMS_PER_PAGE,
take: ITEMS_PER_PAGE,
orderBy: { name: "asc" }
}),
prisma.application.count(),
prisma.server.findMany()
]);
const servers = await prisma.server.findMany({
where: {
id: {
in: serverIds
}
}
});
const serverIds = applications
.map((app: { serverId: number | null }) => app.serverId)
.filter((id:any): id is number => id !== null);
const servers_all = await prisma.server.findMany()
const servers = await prisma.server.findMany({
where: { id: { in: serverIds } }
});
const applicationsWithServers = applications.map(app => ({
...app,
server: servers.find(s => s.id === app.serverId)?.name || 'No server'
}));
const applicationsWithServers = applications.map((app: any) => ({
...app,
server: servers.find((s: any) => s.id === app.serverId)?.name || "No server"
}));
const totalCount = await prisma.application.count();
const maxPage = Math.ceil(totalCount / ITEMS_PER_PAGE);
const maxPage = Math.ceil(totalCount / ITEMS_PER_PAGE);
return NextResponse.json({
applications: applicationsWithServers,
servers: servers_all,
maxPage
});
} catch (error: any) {
return NextResponse.json({ error: error.message }, { status: 500 });
}
return NextResponse.json({
applications: applicationsWithServers,
servers: servers_all,
maxPage
});
} catch (error: unknown) {
const message = error instanceof Error ? error.message : "Unknown error";
return NextResponse.json({ error: message }, { status: 500 });
}
}