mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
Applications need a Server
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user