Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

747 B
Raw Blame
import { withWorkspace } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { getDomainsCountQuerySchema } from "@/lib/zod/schemas/domains";
import { NextResponse } from "next/server";

// GET /api/domains/count – get the number of domains for a workspace
export const GET = withWorkspace(
  async ({ headers, searchParams, workspace }) => {
    const { archived, search } = getDomainsCountQuerySchema.parse(searchParams);

    const count = await prisma.domain.count({
      where: {
        projectId: workspace.id,
        archived,
        ...(search && { slug: { contains: search } }),
      },
    });

    return NextResponse.json(count, {
      headers,
    });
  },
  {
    requiredPermissions: ["domains.read"],
  },
);