From 408b80badf52142c4bf3845fcf2dbff5c2640011 Mon Sep 17 00:00:00 2001 From: headlessdev Date: Fri, 25 Apr 2025 22:13:24 +0200 Subject: [PATCH] Fix allocated server not showing in applications search result --- app/api/applications/search/route.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/api/applications/search/route.ts b/app/api/applications/search/route.ts index e9f6ec0..c2d7ef2 100644 --- a/app/api/applications/search/route.ts +++ b/app/api/applications/search/route.ts @@ -23,7 +23,23 @@ export async function POST(request: NextRequest) { const searchResults = fuse.search(searchterm); - const results = searchResults.map(({ item }) => item); + const searchedApps = searchResults.map(({ item }) => item); + + // Get server IDs from the search results + const serverIds = searchedApps + .map(app => app.serverId) + .filter((id): id is number => id !== null); + + // Fetch server data for these applications + const servers = await prisma.server.findMany({ + where: { id: { in: serverIds } } + }); + + // Add server name to each application + const results = searchedApps.map(app => ({ + ...app, + server: servers.find(s => s.id === app.serverId)?.name || "No server" + })); return NextResponse.json({ results }); } catch (error: any) {