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.

update links metadata in tinybird after deleting a tag

Steven Teyfe64d4ea466d
diff --git a/apps/web/app/api/tags/[id]/route.ts b/apps/web/app/api/tags/[id]/route.ts
index 1b8203876e..ee8f895522 100644
--- a/apps/web/app/api/tags/[id]/route.ts
+++ b/apps/web/app/api/tags/[id]/route.ts
@@ -1,6 +1,7 @@
-import { withAuth } from "@/lib/auth";
import { DubApiError } from "@/lib/api/errors";
+import { withAuth } from "@/lib/auth";
import prisma from "@/lib/prisma";
+import { recordLink } from "@/lib/tinybird";
import { updateTagBodySchema } from "@/lib/zod/schemas/tags";
import { NextResponse } from "next/server";
@@ -53,7 +54,29 @@ export const DELETE = withAuth(async ({ params }) => {
where: {
id,
},
+ include: {
+ linksNew: true,
+ },
});
+
+ // update links metadata in tinybird after deleting a tag
+ await Promise.all(
+ response.linksNew.map(async ({ linkId }) => {
+ const link = await prisma.link.findUnique({
+ where: {
+ id: linkId,
+ },
+ include: {
+ tags: true,
+ },
+ });
+ if (!link) {
+ return null;
+ }
+ return await recordLink({ link });
+ }),
+ );
+
return NextResponse.json(response);
} catch (error) {
if (error.code === "P2025") {