2024-11-24 18:44:19 -06:00

19 lines
547 B
TypeScript

import { NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
export async function GET() {
try {
// Get unique controllers with their latest session
const controllers = await prisma.controllerSession.findMany({
orderBy: {
lastSeen: 'desc',
},
distinct: ['cid'],
})
return NextResponse.json(controllers)
} catch (error) {
console.error('Failed to fetch controller data:', error)
return NextResponse.json({ error: 'Failed to fetch controller data' }, { status: 500 })
}
}