36 lines
854 B
TypeScript
36 lines
854 B
TypeScript
import { fetchTerms } from "features/study/queries/CRUD-Terms";
|
|
import { NextResponse } from "next/server";
|
|
|
|
|
|
export async function GET(request: Request) {
|
|
const url = new URL(request.url);
|
|
const moduleidParam = url.searchParams.get("moduleid");
|
|
|
|
if (!moduleidParam) {
|
|
return NextResponse.json(
|
|
{ error: "Missing moduleid parameter" },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
const moduleid = parseInt(moduleidParam, 10);
|
|
|
|
if (isNaN(moduleid)) {
|
|
return NextResponse.json(
|
|
{ error: "Invalid moduleid parameter" },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
try {
|
|
const terms = await fetchTerms(moduleid);
|
|
|
|
return NextResponse.json(terms);
|
|
} catch (error) {
|
|
console.error("Error in GET /api/terms:", error);
|
|
|
|
return NextResponse.json(
|
|
{ error: "Failed to fetch terms" },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
}
|