import { NextResponse } from "next/server";
import { prisma } from "@repo/db";

export async function GET(): Promise<NextResponse> {
	try {
		const connectedDispatcher = await prisma.connectedDispatcher.findMany({
			where: {
				logoutTime: null,
			},
		});

		const connectedAircraft = await prisma.connectedAircraft.findMany({
			where: {
				logoutTime: null,
			},
		});

		return NextResponse.json([...connectedDispatcher, ...connectedAircraft], {
			status: 200,
		});
	} catch (error) {
		console.error(error);
		return NextResponse.json(
			{ error: "Failed to fetch connected User" },
			{ status: 500 },
		);
	}
}
