import type { Service, Heartbeat } from '$lib/types'; export interface EnhancedService extends Service { heartbeats: Heartbeat[]; } export async function load({ fetch }) { let services: EnhancedService[] = []; let error = ''; try { const res = await fetch('/api/services'); if (!res.ok) throw new Error(`HTTP ${res.status}`); const list: Service[] = await res.json(); services = await Promise.all( list.map(async (svc) => { try { const hres = await fetch(`/api/services/${svc.id}/history`); if (!hres.ok) throw new Error(`HTTP ${hres.status}`); const heartbeats: Heartbeat[] = await hres.json(); return { ...svc, heartbeats }; } catch { return { ...svc, heartbeats: [] }; } }) ); } catch (e) { error = 'Não foi possível conectar ao servidor'; } return { services, error }; }