10 lines
508 B
TypeScript
10 lines
508 B
TypeScript
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 });
|
||
|
|
}
|