Files
chocoadmin/app/api/maestros/[id]/route.ts
T

26 lines
652 B
TypeScript

import { NextResponse } from "next/server";
import { getMaestroDetail } from "@/lib/maestros";
import { ApiError } from "@/lib/errors";
import { withApiHandler } from "@/lib/api-handler";
export const GET = withApiHandler<{ id: string }>(
"maestros/[id]",
async (_request, { params }) => {
const { id } = await params;
const maestroID = Number(id);
if (!Number.isInteger(maestroID) || maestroID <= 0) {
throw new ApiError("Invalid maestro id", 400);
}
const result = await getMaestroDetail(maestroID);
if (!result) {
throw new ApiError("Not found", 404);
}
return NextResponse.json(result);
}
);