29 lines
1 KiB
TypeScript
29 lines
1 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { reorderRequestSchema } from "@/lib/validation/reorderSchemas";
|
|
import {
|
|
ReorderConflictError,
|
|
ReorderValidationError,
|
|
reorderContent,
|
|
} from "@/services/reorderService";
|
|
|
|
export async function PATCH(request: NextRequest) {
|
|
const parsed = reorderRequestSchema.safeParse(
|
|
await request.json().catch(() => null)
|
|
);
|
|
if (!parsed.success) {
|
|
return NextResponse.json({ error: "Invalid reorder input" }, { status: 400 });
|
|
}
|
|
try {
|
|
await reorderContent("QUIZ", parsed.data);
|
|
return NextResponse.json({ success: true });
|
|
} catch (error) {
|
|
if (error instanceof ReorderValidationError) {
|
|
return NextResponse.json({ error: error.message }, { status: 400 });
|
|
}
|
|
if (error instanceof ReorderConflictError) {
|
|
return NextResponse.json({ error: error.message }, { status: 409 });
|
|
}
|
|
console.error("Failed to reorder quizzes", error);
|
|
return NextResponse.json({ error: "Failed to reorder quizzes" }, { status: 500 });
|
|
}
|
|
}
|