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.

1.1 KB
Raw Blame
import { prisma } from "@/lib/prisma";
import type { WebhookTrigger } from "./types";

interface GetWebhooksProps {
  workspaceId: string;
  triggers?: WebhookTrigger[];
  disabled?: boolean;
  installationId?: string | null; // null = user-added webhooks, string = specific installation, undefined = no filter
}

export async function getWebhooks({
  workspaceId,
  triggers,
  disabled,
  installationId,
}: GetWebhooksProps) {
  return await prisma.webhook.findMany({
    where: {
      projectId: workspaceId,
      ...(triggers ? { triggers: { array_contains: triggers } } : {}),
      ...(disabled !== undefined
        ? { disabledAt: disabled ? { not: null } : null }
        : {}),
      ...(installationId !== undefined
        ? { installationId: installationId === null ? null : installationId }
        : {}),
    },
    select: {
      id: true,
      name: true,
      url: true,
      secret: true,
      triggers: true,
      linkScope: true,
      disabledAt: true,
      receiver: true,
      installationId: true,
    },
    orderBy: {
      createdAt: "desc",
    },
  });
}