Added route for position update

This commit is contained in:
PxlLoewe
2025-05-09 12:17:29 -07:00
parent 654bdfbbaa
commit d562056dc2
4 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
import { Prisma, prisma } from "@repo/db";
import { getServerSession } from "api/auth/[...nextauth]/auth";
export const PUT = async (req: Request) => {
const session = await getServerSession();
if (!session)
return Response.json({ message: "Unauthorized" }, { status: 401 });
const { position, h145 } = (await req.json()) as {
position: Prisma.PositionLogCreateInput;
h145: boolean;
};
if (!position) {
return Response.json(
{ message: "Missing id or position" },
{ status: 400 },
);
}
const positionLog = await prisma.positionLog.create({
data: position,
});
const activeAircraft = await prisma.connectedAircraft.findFirst({
where: {
userId: session.user.id,
logoutTime: null,
},
orderBy: {
loginTime: "desc",
},
select: {
id: true,
},
});
await prisma.connectedAircraft.update({
where: {
id: activeAircraft?.id,
},
data: {
lastHeartbeat: new Date(),
posAlt: positionLog.alt,
posLat: positionLog.lat,
posLng: positionLog.lng,
posHeading: positionLog.heading,
posSpeed: positionLog.speed,
posH145active: h145,
positionLogIds: {
push: positionLog.id,
},
},
});
return Response.json(positionLog);
};

View File

@@ -21,6 +21,7 @@ export const GET = async (req: NextRequest) => {
id: decoded.id,
},
});
if (!user)
return NextResponse.json({ error: "User not found" }, { status: 404 });
setTimeout(async () => {