import { NextRequest, NextResponse } from 'next/server' import { getServerSession } from 'next-auth' import { authOptions } from '@/lib/auth' import { prisma } from '@/lib/prisma' export async function GET(req: NextRequest) { const session = await getServerSession(authOptions) if (!session) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) const { searchParams } = new URL(req.url) const clientId = searchParams.get('clientId') const failed = await prisma.smsQueue.findMany({ where: { status: 'FAILED', ...(clientId ? { clientId } : {}), }, include: { client: { select: { name: true } } }, orderBy: { updatedAt: 'desc' }, take: 200, }) return NextResponse.json(failed) }