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.

rename methods

Kiran K5cd66704205d
diff --git a/apps/web/app/api/webhooks/[webhookId]/route.ts b/apps/web/app/api/webhooks/[webhookId]/route.ts
index 1fd6d2f1c1..1895aab24a 100644
--- a/apps/web/app/api/webhooks/[webhookId]/route.ts
+++ b/apps/web/app/api/webhooks/[webhookId]/route.ts
@@ -4,7 +4,7 @@ import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
import { webhookCache } from "@/lib/webhook/cache";
import { transformWebhook } from "@/lib/webhook/transform";
-import { updateWebhookStatusForWorkspace } from "@/lib/webhook/update-webhook";
+import { toggleWebhooksForWorkspace } from "@/lib/webhook/update-webhook";
import { isLinkLevelWebhook } from "@/lib/webhook/utils";
import { updateWebhookSchema } from "@/lib/zod/schemas/webhooks";
import { prisma } from "@dub/prisma";
@@ -314,7 +314,7 @@ export const DELETE = withWorkspace(
});
await Promise.all([
- updateWebhookStatusForWorkspace({
+ toggleWebhooksForWorkspace({
workspaceId: workspace.id,
}),
diff --git a/apps/web/app/api/webhooks/route.ts b/apps/web/app/api/webhooks/route.ts
index 9c5795de7b..82bc39db4f 100644
--- a/apps/web/app/api/webhooks/route.ts
+++ b/apps/web/app/api/webhooks/route.ts
@@ -3,7 +3,7 @@ import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
import { createWebhook } from "@/lib/webhook/create-webhook";
import { transformWebhook } from "@/lib/webhook/transform";
-import { updateWebhookStatusForWorkspace } from "@/lib/webhook/update-webhook";
+import { toggleWebhooksForWorkspace } from "@/lib/webhook/update-webhook";
import { identifyWebhookReceiver } from "@/lib/webhook/utils";
import { createWebhookSchema } from "@/lib/zod/schemas/webhooks";
import { prisma } from "@dub/prisma";
@@ -128,7 +128,7 @@ export const POST = withWorkspace(
waitUntil(
Promise.allSettled([
- updateWebhookStatusForWorkspace({
+ toggleWebhooksForWorkspace({
workspaceId: workspace.id,
}),
diff --git a/apps/web/lib/actions/enable-disable-webhook.ts b/apps/web/lib/actions/enable-disable-webhook.ts
index 8dbf93da46..e097aa130f 100644
--- a/apps/web/lib/actions/enable-disable-webhook.ts
+++ b/apps/web/lib/actions/enable-disable-webhook.ts
@@ -3,7 +3,7 @@
import { prisma } from "@dub/prisma";
import { waitUntil } from "@vercel/functions";
import { webhookCache } from "../webhook/cache";
-import { updateWebhookStatusForWorkspace } from "../webhook/update-webhook";
+import { toggleWebhooksForWorkspace } from "../webhook/update-webhook";
import z from "../zod";
import { authActionClient } from "./safe-action";
@@ -50,7 +50,7 @@ export const enableOrDisableWebhook = authActionClient
waitUntil(
(async () => {
await Promise.all([
- updateWebhookStatusForWorkspace({
+ toggleWebhooksForWorkspace({
workspaceId: workspace.id,
}),
diff --git a/apps/web/lib/webhook/api.ts b/apps/web/lib/webhook/api.ts
index 2b06815b9e..2af04c6f6a 100644
--- a/apps/web/lib/webhook/api.ts
+++ b/apps/web/lib/webhook/api.ts
@@ -100,25 +100,3 @@ export async function addWebhook({
return webhook;
}
-
-export const updateWebhookStatusForWorkspace = async ({
- workspace,
-}: {
- workspace: Pick<Project, "id">;
-}) => {
- const activeWebhooksCount = await prisma.webhook.count({
- where: {
- projectId: workspace.id,
- disabledAt: null,
- },
- });
-
- await prisma.project.update({
- where: {
- id: workspace.id,
- },
- data: {
- webhookEnabled: activeWebhooksCount > 0,
- },
- });
-};
diff --git a/apps/web/lib/webhook/failure.ts b/apps/web/lib/webhook/failure.ts
index 68757b147c..d08e8a4e8f 100644
--- a/apps/web/lib/webhook/failure.ts
+++ b/apps/web/lib/webhook/failure.ts
@@ -4,7 +4,7 @@ import { sendEmail } from "emails";
import WebhookDisabled from "emails/webhook-disabled";
import { webhookCache } from "./cache";
import { WEBHOOK_FAILURE_NOTIFY_THRESHOLD } from "./constants";
-import { updateWebhookStatusForWorkspace } from "./update-webhook";
+import { toggleWebhooksForWorkspace } from "./update-webhook";
export const handleWebhookFailure = async (webhookId: string) => {
const webhook = await prisma.webhook.update({
@@ -49,7 +49,7 @@ export const handleWebhookFailure = async (webhookId: string) => {
webhookCache.set(updatedWebhook),
// Update the project webhookEnabled flag
- updateWebhookStatusForWorkspace({
+ toggleWebhooksForWorkspace({
workspaceId: webhook.projectId,
}),
]);
diff --git a/apps/web/lib/webhook/update-webhook.ts b/apps/web/lib/webhook/update-webhook.ts
index c8dfb4ce6a..d116f00e9a 100644
--- a/apps/web/lib/webhook/update-webhook.ts
+++ b/apps/web/lib/webhook/update-webhook.ts
@@ -1,6 +1,7 @@
import { prisma } from "@dub/prisma";
-export const updateWebhookStatusForWorkspace = async ({
+// Based on the webhook count, we toggle the webhook status for the workspace
+export const toggleWebhooksForWorkspace = async ({
workspaceId,
}: {
workspaceId: string;