added filter to aircrafts query
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
PORT=3002
|
DISPATCH_SERVER_PORT=3002
|
||||||
REDIS_HOST=localhost
|
REDIS_HOST=localhost
|
||||||
REDIS_PORT=6379
|
REDIS_PORT=6379
|
||||||
DISPATCH_APP_TOKEN=dispatch
|
DISPATCH_APP_TOKEN=dispatch
|
||||||
|
|||||||
@@ -1,11 +1,18 @@
|
|||||||
import { NextResponse } from "next/server";
|
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 {
|
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({
|
const connectedAircraft = await prisma.connectedAircraft.findMany({
|
||||||
where: {
|
where: {
|
||||||
logoutTime: null,
|
logoutTime: null,
|
||||||
|
...filter, // Ensure filter is parsed correctly
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
Station: true,
|
Station: true,
|
||||||
@@ -17,9 +24,6 @@ export async function GET(): Promise<NextResponse> {
|
|||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return NextResponse.json(
|
return NextResponse.json({ error: "Failed to fetch Aircrafts" }, { status: 500 });
|
||||||
{ error: "Failed to fetch Aircrafts" },
|
|
||||||
{ status: 500 },
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user