diff --git a/apps/dispatch/app/api/livekit/token/route.ts b/apps/dispatch/app/api/keywords/token/route.ts similarity index 100% rename from apps/dispatch/app/api/livekit/token/route.ts rename to apps/dispatch/app/api/keywords/token/route.ts diff --git a/apps/dispatch/app/api/position-log/route.ts b/apps/dispatch/app/api/position-log/route.ts new file mode 100644 index 00000000..7951c8a9 --- /dev/null +++ b/apps/dispatch/app/api/position-log/route.ts @@ -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); +}; diff --git a/apps/hub/app/api/user/route.ts b/apps/hub/app/api/user/route.ts index cf101c40..ad7d67d7 100644 --- a/apps/hub/app/api/user/route.ts +++ b/apps/hub/app/api/user/route.ts @@ -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 () => { diff --git a/grafana/grafana.db b/grafana/grafana.db index 26692ff7..60aadc35 100644 Binary files a/grafana/grafana.db and b/grafana/grafana.db differ