added filter to aircrafts query

This commit is contained in:
PxlLoewe
2025-06-01 10:13:42 -07:00
parent e73f19d9e8
commit 9c4c51f274
2 changed files with 11 additions and 7 deletions

View File

@@ -1,11 +1,18 @@
import { NextResponse } from "next/server";
import { prisma } from "@repo/db";
import { Prisma, prisma } from "@repo/db";
export async function GET(): Promise<NextResponse> {
export async function GET(request: Request): Promise<NextResponse> {
try {
console.log(new URL(request.url).searchParams.get("filter"));
const filter = JSON.parse(
new URL(request.url).searchParams.get("filter") || "{}",
) as Prisma.ConnectedAircraftWhereInput;
console.log("Filter:", filter);
const connectedAircraft = await prisma.connectedAircraft.findMany({
where: {
logoutTime: null,
...filter, // Ensure filter is parsed correctly
},
include: {
Station: true,
@@ -17,9 +24,6 @@ export async function GET(): Promise<NextResponse> {
});
} catch (error) {
console.error(error);
return NextResponse.json(
{ error: "Failed to fetch Aircrafts" },
{ status: 500 },
);
return NextResponse.json({ error: "Failed to fetch Aircrafts" }, { status: 500 });
}
}