The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update route.ts
Kiran Kb4f8bdb1b73b
diff --git a/apps/web/app/(ee)/api/embed/referrals/links/[linkId]/route.ts b/apps/web/app/(ee)/api/embed/referrals/links/[linkId]/route.tsindex ae782c1446..4120bc084a 100644--- a/apps/web/app/(ee)/api/embed/referrals/links/[linkId]/route.ts+++ b/apps/web/app/(ee)/api/embed/referrals/links/[linkId]/route.ts@@ -5,6 +5,7 @@ import { parseRequestBody } from "@/lib/api/utils";import { withReferralsEmbedToken } from "@/lib/embed/referrals/auth";import { createPartnerLinkSchema } from "@/lib/zod/schemas/partners";import { ReferralsEmbedLinkSchema } from "@/lib/zod/schemas/referrals-embed";+import { getUrlWithoutUTMParams } from "@dub/utils";import { NextResponse } from "next/server";// PATCH /api/embed/referrals/links/[linkId] - update a link for a partner@@ -38,6 +39,27 @@ export const PATCH = withReferralsEmbedToken(});}+ // prevent updating the default partner link+ const defaultLinks = links.filter(({ url }) =>+ group.defaultLinks.find(+ (defaultLink) =>+ defaultLink.url === getUrlWithoutUTMParams(url) &&+ defaultLink.url === getUrlWithoutUTMParams(link.url),+ ),+ );++ if (defaultLinks.length > 0) {+ const defaultLink = defaultLinks[0];++ if (defaultLink?.id === link.id) {+ throw new DubApiError({+ code: "forbidden",+ message:+ "You cannot update the default partner link. Please contact us if you think this is an error.",+ });+ }+ }+validatePartnerLinkUrl({ group, url });// if domain and key are the same, we don't need to check if the key exists