Files
var-monorepo/apps/hub/app/api/stations/route.ts
2025-09-20 22:16:23 +02:00

33 lines
847 B
TypeScript

import { NextResponse } from "next/server";
import { prisma } from "@repo/db";
import { getServerSession } from "../auth/[...nextauth]/auth";
// GET /api/station - Get all stations for booking selection
export const GET = async () => {
try {
const session = await getServerSession();
if (!session?.user) {
return NextResponse.json({ error: "Not authenticated" }, { status: 401 });
}
const stations = await prisma.station.findMany({
select: {
id: true,
bosCallsign: true,
bosCallsignShort: true,
locationState: true,
operator: true,
aircraft: true,
},
orderBy: {
bosCallsignShort: "asc",
},
});
return NextResponse.json(stations);
} catch (error) {
console.error("Error fetching stations:", error);
return NextResponse.json({ error: "Internal server error" }, { status: 500 });
}
};