40 lines
844 B
TypeScript
40 lines
844 B
TypeScript
import { NextResponse } from "next/server";
|
|
|
|
import { auth } from "@/auth";
|
|
import { getMaestroDetail } from "@/lib/maestros";
|
|
|
|
type MaestroDetailRouteContext = {
|
|
params: Promise<{
|
|
id: string;
|
|
}>;
|
|
};
|
|
|
|
export async function GET(
|
|
_request: Request,
|
|
{ params }: MaestroDetailRouteContext
|
|
) {
|
|
const session = await auth();
|
|
|
|
if (!session) {
|
|
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
|
|
}
|
|
|
|
const { id } = await params;
|
|
const maestroID = Number(id);
|
|
|
|
if (!Number.isInteger(maestroID) || maestroID <= 0) {
|
|
return NextResponse.json(
|
|
{ message: "Invalid maestro id" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
const result = await getMaestroDetail(maestroID);
|
|
|
|
if (!result) {
|
|
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
|
}
|
|
|
|
return NextResponse.json(result);
|
|
}
|