Files
Vault/app/api/comments/reply/[replyId]/route.ts
T
twotalesanimation 81ad7e4ea9 Initial commit
2026-06-11 10:46:09 +02:00

36 lines
1001 B
TypeScript

import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth-options';
import { prisma } from '@/lib/prisma';
import { NextRequest, NextResponse } from 'next/server';
export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ replyId: string }> }
) {
const { replyId } = await params;
const session = await getServerSession(authOptions);
if (!session?.user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const role = (session.user as any).role;
if (role !== 'admin' && role !== 'superadmin') {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
}
try {
const reply = await prisma.commentReply.delete({
where: { id: replyId },
});
return NextResponse.json({ success: true });
} catch (error) {
console.error('Failed to delete reply:', error);
return NextResponse.json(
{ error: 'Failed to delete reply' },
{ status: 500 }
);
}
}