Add fallback for the last_active date for devices without heartbeats

Return the board date of the device as fallback.

Issue: HIC-206
Change-Id: I58090e9448aedf1f0dfac4ea0b39f11b941ed109
diff --git a/crashreport_stats/rest_endpoints.py b/crashreport_stats/rest_endpoints.py
index d1dec33..f24b625 100644
--- a/crashreport_stats/rest_endpoints.py
+++ b/crashreport_stats/rest_endpoints.py
@@ -268,10 +268,14 @@
 
         """
         device = Device.objects.filter(uuid=uuid)
-        last_active = (
-            HeartBeat.objects.filter(device=device).order_by("-date")[0].date
-        )
-        heartbeats = HeartBeat.objects.filter(device=device).count()
+
+        heartbeat_instances = HeartBeat.objects.filter(device=device)
+        if heartbeat_instances.exists():
+            last_active = heartbeat_instances.order_by("-date")[0].date
+        else:
+            last_active = device[0].board_date
+
+        heartbeats = heartbeat_instances.count()
         crashreports = (
             Crashreport.objects.filter(device=device)
             .filter(boot_reason__in=Crashreport.CRASH_BOOT_REASONS)