fix: add getDevice query, fix IN clause, add error handling to getDeviceStats

This commit is contained in:
Sanju Sivalingam
2026-02-17 21:13:50 +05:30
parent b240887b0e
commit 423cd7af01
2 changed files with 66 additions and 34 deletions

View File

@@ -1,7 +1,7 @@
<script lang="ts">
import { page } from '$app/state';
import {
listDevices,
getDevice,
listDeviceSessions,
listSessionSteps,
getDeviceStats
@@ -15,15 +15,25 @@
let activeTab = $state<'overview' | 'sessions' | 'run'>('overview');
// Device data from DB
const allDevices = await listDevices();
const deviceData = allDevices.find((d) => d.deviceId === deviceId);
const deviceData = (await getDevice(deviceId)) as {
deviceId: string;
name: string;
status: string;
model: string | null;
manufacturer: string | null;
androidVersion: string | null;
screenWidth: number | null;
screenHeight: number | null;
batteryLevel: number | null;
isCharging: boolean;
lastSeen: string;
} | null;
// Device stats
const stats = (await getDeviceStats(deviceId)) as {
totalSessions: number;
successRate: number;
avgSteps: number;
lastGoal: { goal: string; status: string; startedAt: Date } | null;
} | null;
// Session history