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.

fix bulk create/update webhooks

Kiran K733321db769c
diff --git a/apps/web/app/api/links/bulk/route.ts b/apps/web/app/api/links/bulk/route.ts
index 1f50b87961..b88d6bd5aa 100644
--- a/apps/web/app/api/links/bulk/route.ts
+++ b/apps/web/app/api/links/bulk/route.ts
@@ -162,7 +162,7 @@ export const POST = withWorkspace(
const webhookIds = validLinks
.map((link) => link.webhookIds)
.flat()
- .filter((id): id is string => id !== null);
+ .filter(Boolean) as string[];
const webhooks = await prisma.webhook.findMany({
where: { projectId: workspace.id, id: { in: webhookIds } },
diff --git a/apps/web/lib/api/links/bulk-update-links.ts b/apps/web/lib/api/links/bulk-update-links.ts
index 3e6a23bc25..918c2b0296 100644
--- a/apps/web/lib/api/links/bulk-update-links.ts
+++ b/apps/web/lib/api/links/bulk-update-links.ts
@@ -28,6 +28,7 @@ export async function bulkUpdateLinks(
tagId,
tagIds,
tagNames,
+ webhookIds,
...rest
} = data;
@@ -83,6 +84,16 @@ export async function bulkUpdateLinks(
})),
},
}),
+
+ // Associate webhooks
+ ...(webhookIds && {
+ webhooks: {
+ deleteMany: {},
+ create: webhookIds.map((webhookId) => ({
+ webhookId,
+ })),
+ },
+ }),
},
include: {
tags: {
@@ -100,6 +111,7 @@ export async function bulkUpdateLinks(
createdAt: "asc",
},
},
+ webhooks: webhookIds ? { select: { webhookId: true } } : false,
},
}),
),