diff --git a/apps/dispatch/app/api/position-log/route.ts b/apps/dispatch/app/api/position-log/route.ts index 7951c8a9..47d7eb4c 100644 --- a/apps/dispatch/app/api/position-log/route.ts +++ b/apps/dispatch/app/api/position-log/route.ts @@ -16,10 +16,6 @@ export const PUT = async (req: Request) => { ); } - const positionLog = await prisma.positionLog.create({ - data: position, - }); - const activeAircraft = await prisma.connectedAircraft.findFirst({ where: { userId: session.user.id, @@ -33,6 +29,16 @@ export const PUT = async (req: Request) => { }, }); + if (!activeAircraft) { + return Response.json( + { message: "No active aircraft found" }, + { status: 400 }, + ); + } + const positionLog = await prisma.positionLog.create({ + data: position, + }); + await prisma.connectedAircraft.update({ where: { id: activeAircraft?.id, diff --git a/apps/dispatch/app/dispatch/_components/map/SearchElements.tsx b/apps/dispatch/app/dispatch/_components/map/SearchElements.tsx index fb8068ca..7fec4a48 100644 --- a/apps/dispatch/app/dispatch/_components/map/SearchElements.tsx +++ b/apps/dispatch/app/dispatch/_components/map/SearchElements.tsx @@ -41,13 +41,14 @@ export const SearchElements = () => { element: (typeof searchElements)[1]; isActive?: boolean; }) => { - const ref = useRef(null); + const ref = useRef(null); useEffect(() => { if (ref.current) { ref.current.on("click", () => { - const center = ref.current.getBounds().getCenter(); - if (searchPopup?.elementId !== element.wayID) { + console.log("click"); + const center = ref.current?.getBounds().getCenter(); + if (center && searchPopup?.elementId !== element.wayID) { setSearchPopup({ lat: center.lat, lng: center.lng, @@ -130,6 +131,16 @@ export const SearchElements = () => { ); })} {searchElements.map((element, i) => { + if ( + missions.data?.some( + (mission) => + (mission.addressOSMways as (OSMWay | null)[]) + .filter((e): e is OSMWay => e !== null) + .some((e) => e.wayID === element.wayID) && + openMissionMarker.some((m) => m.id === mission.id), + ) + ) + return null; return (