Added HPG validation

This commit is contained in:
PxlLoewe
2025-06-03 13:44:21 -07:00
parent 4acdb48344
commit ebb72c6517
14 changed files with 223 additions and 116 deletions

View File

@@ -0,0 +1,33 @@
import { prisma, Prisma } from "@repo/db";
import { NextRequest, NextResponse } from "next/server";
export async function GET(request: NextRequest): Promise<NextResponse> {
try {
const connectedAircraftId = request.nextUrl.searchParams.get("connectedAircraftId");
const aircraft = await prisma.connectedAircraft.findUnique({
where: {
id: connectedAircraftId ? parseInt(connectedAircraftId) : undefined,
},
});
if (!aircraft) return NextResponse.json({ error: "Aircraft not found" }, { status: 404 });
const positionLog = await prisma.positionLog.findMany({
where: {
id: {
in: aircraft.positionLogIds,
},
timestamp: {
gte: new Date(Date.now() - 2 * 60 * 60 * 1000), // Last 2 hours
},
},
});
return NextResponse.json(positionLog, {
status: 200,
});
} catch (error) {
console.error(error);
return NextResponse.json({ error: "Failed to fetch Aircrafts" }, { status: 500 });
}
}