added filter to aircrafts query
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
PORT=3002
|
||||
DISPATCH_SERVER_PORT=3002
|
||||
REDIS_HOST=localhost
|
||||
REDIS_PORT=6379
|
||||
DISPATCH_APP_TOKEN=dispatch
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user