import { NextResponse } from "next/server"; import { getDeviceCommandCounts, getDeviceUsageStats } from "@/lib/db/queries/stats"; export async function GET() { const [usage, commandCounts] = await Promise.all([getDeviceUsageStats(), getDeviceCommandCounts()]); const commandCountByDevice = new Map(commandCounts.map((c) => [c.deviceId, c.commandCount])); const devices = usage.map((d) => ({ ...d, commandCount: commandCountByDevice.get(d.deviceId) ?? 0 })); return NextResponse.json({ devices }); }