import { NextRequest, NextResponse } from "next/server" import { getSessionUser } from "@/lib/auth" import { query } from "@/lib/db" export async function GET(request: NextRequest, { params }: { params: Promise<{ id: string }> }) { try { const user = await getSessionUser() if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 }) const { id } = await params const result = await query( `SELECT l.*, s.contact_name, s.email AS subscriber_email FROM email_campaign_logs l LEFT JOIN email_campaign_subscribers s ON s.id = l.subscriber_id WHERE l.campaign_id = $1 ORDER BY l.sent_at DESC LIMIT 100`, [id] ) return NextResponse.json(result.rows) } catch (error) { return NextResponse.json({ error: "Failed" }, { status: 500 }) } }