diff --git a/src/meshapi/tests/test_map_endpoints.py b/src/meshapi/tests/test_map_endpoints.py index ac5cf160..7e506d2f 100644 --- a/src/meshapi/tests/test_map_endpoints.py +++ b/src/meshapi/tests/test_map_endpoints.py @@ -364,6 +364,15 @@ def test_install_data(self): ) ) + nodes.append( + Node( + network_number=9820, + status=Node.NodeStatus.ACTIVE, + latitude=40.724868, + longitude=-73.987881, + ) + ) + for node in nodes: node.save() @@ -430,6 +439,14 @@ def test_install_data(self): "roofAccess": True, "panoramas": [], }, + { + "coordinates": [-73.987881, 40.724868, None], + "id": 9820, + "panoramas": [], + "requestDate": None, + "roofAccess": True, + "status": "NN assigned", + }, { "coordinates": [-73.987881, 40.724868, None], "id": 9821, diff --git a/src/meshapi/views/map.py b/src/meshapi/views/map.py index a2dd4d14..228c7019 100644 --- a/src/meshapi/views/map.py +++ b/src/meshapi/views/map.py @@ -12,7 +12,7 @@ from rest_framework.response import Response from rest_framework.views import APIView -from meshapi.models import LOS, AccessPoint, Device, Install, Link, Node, Sector +from meshapi.models import LOS, AccessPoint, Building, Device, Install, Link, Node, Sector from meshapi.serializers import ( EXCLUDED_INSTALL_STATUSES, MapDataInstallSerializer, @@ -98,6 +98,20 @@ def get_queryset(self) -> List[Install]: # type: ignore[override] except IndexError: representative_install = None + if representative_install: + building = representative_install.building + else: + building = node.buildings.first() + + if not building: + # If we couldn't get a building from the install or node, + # make a faux one instead, to carry the lat/lon info into the serializer + building = Building( + latitude=node.latitude, + longitude=node.longitude, + altitude=node.altitude, + ) + all_installs.append( Install( install_number=node.network_number, @@ -105,7 +119,7 @@ def get_queryset(self) -> List[Install]: # type: ignore[override] status=Install.InstallStatus.NN_REASSIGNED if node.status == node.NodeStatus.ACTIVE else Install.InstallStatus.REQUEST_RECEIVED, - building=representative_install.building if representative_install else node.buildings.first(), + building=building, request_date=representative_install.request_date if representative_install else node.install_date,