33 lines
851 B
TypeScript
33 lines
851 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 });
|
|
}
|
|
};
|