Applications need a Server

This commit is contained in:
headlessdev
2025-04-12 13:19:52 +02:00
parent 0506731a12
commit 43b7b3b270
12 changed files with 200 additions and 105 deletions

View File

@@ -2,6 +2,7 @@ import { NextResponse, NextRequest } from "next/server";
import { PrismaClient } from '@/lib/generated/prisma'
interface AddRequest {
serverId: number;
name: string;
description: string;
icon: string;
@@ -14,10 +15,11 @@ const prisma = new PrismaClient();
export async function POST(request: NextRequest) {
try {
const body: AddRequest = await request.json();
const { name, description, icon, publicURL, localURL } = body;
const { serverId, name, description, icon, publicURL, localURL } = body;
const application = await prisma.application.create({
data: {
serverId,
name,
description,
icon,

View File

@@ -19,11 +19,29 @@ export async function POST(request: NextRequest) {
orderBy: { name: 'asc' }
});
const serverIds = applications
.map(app => app.serverId)
.filter((id): id is number => id !== null);
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 totalCount = await prisma.application.count();
const maxPage = Math.ceil(totalCount / ITEMS_PER_PAGE);
return NextResponse.json({
applications,
applications: applicationsWithServers,
servers,
maxPage
});
} catch (error: any) {