import { auth } from "@/lib/auth"; import { prisma } from "@/lib/prisma"; import { getActiveAppId } from "@/lib/active-app"; export async function GET(request: Request) { const session = await auth(); if (!session) return new Response("Unauthorized", { status: 401 }); const { searchParams } = new URL(request.url); const campaignId = searchParams.get("campaignId"); const type = searchParams.get("type"); const platform = searchParams.get("platform"); const status = searchParams.get("status"); const search = searchParams.get("search"); const appId = await getActiveAppId(); const where: Record = {}; if (campaignId) where.campaignId = campaignId; if (type && type !== "all") where.type = type; if (platform && platform !== "all") where.platform = platform; if (status && status !== "all") where.status = status; if (search) { where.OR = [ { fileName: { contains: search } }, { metadata: { contains: search } }, ]; } // Filter by active app's campaigns if (appId) { where.campaign = { ...((where.campaign as object) || {}), appId }; } const assets = await prisma.asset.findMany({ where, orderBy: { createdAt: "desc" }, include: { campaign: { select: { name: true } } }, }); return Response.json(assets); }