29 lines
726 B
TypeScript
29 lines
726 B
TypeScript
import { NextResponse } from "next/server";
|
|
|
|
import { getMaestroLogs } from "@/lib/maestros";
|
|
import { ApiError } from "@/lib/errors";
|
|
import { withApiHandler } from "@/lib/api-handler";
|
|
|
|
const CTX = "maestros/[id]/logs";
|
|
|
|
export const GET = withApiHandler<{ id: string }>(
|
|
CTX,
|
|
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 url = new URL(request.url);
|
|
const result = await getMaestroLogs(maestroID, url.searchParams);
|
|
|
|
if (!result) {
|
|
throw new ApiError("Not found", 404);
|
|
}
|
|
|
|
return NextResponse.json(result);
|
|
}
|
|
);
|