diff options
Diffstat (limited to 'api/home.ts')
| -rw-r--r-- | api/home.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/api/home.ts b/api/home.ts new file mode 100644 index 0000000..89e1cca --- /dev/null +++ b/api/home.ts @@ -0,0 +1,31 @@ +import { apiClient } from "./client"; +import { HomeData } from "./types"; + +export async function getHomeData(deviceId?: string): Promise<HomeData> { + try { + const endpoint = deviceId ? `/parent/home/${deviceId}` : "/parent/home"; + const response = await apiClient.get<{ + success: boolean; + overallStatus: HomeData["overallStatus"]; + deviceOnline: boolean; + alertStats: HomeData["alertStats"]; + }>(endpoint); + + return { + overallStatus: response.overallStatus, + deviceOnline: response.deviceOnline, + alertStats: response.alertStats, + }; + } catch (e) { + console.error("Failed to fetch home data", e); + // Return default data on error + return { + overallStatus: "all_clear", + deviceOnline: false, + alertStats: { + last24Hours: 0, + thisWeekReviewed: 0, + }, + }; + } +} |