feat: expose tenant-safe dataset describe route
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
|
||||
import { siaxErrorResponse } from "@/src/http/siax-error-response";
|
||||
import { SiaxError } from "@/src/platform/errors";
|
||||
import { datasetService } from "@/src/services/datasets";
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ datasetId: string }> },
|
||||
) {
|
||||
try {
|
||||
const { datasetId } = await params;
|
||||
const tenantId = new URL(request.url).searchParams.get("tenant_id")?.trim();
|
||||
if (!tenantId) throw new SiaxError("INVALID_REQUEST", "0pt.dataset", "tenant_id is required");
|
||||
const guard = assertTenantMatchesVerified(request, tenantId);
|
||||
if (guard) return guard;
|
||||
|
||||
const dataset = await datasetService.getDataset(datasetId);
|
||||
if (dataset.tenant_id !== tenantId) {
|
||||
throw new SiaxError("NOT_FOUND", "0pt.dataset", `dataset ${datasetId} not found`);
|
||||
}
|
||||
return NextResponse.json(dataset);
|
||||
} catch (error: unknown) {
|
||||
return siaxErrorResponse(error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user