The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Prevent deletion of UTM templates linked to groups
Kiran K71558ae9c906
diff --git a/apps/web/app/api/utm/[id]/route.ts b/apps/web/app/api/utm/[id]/route.tsindex 78d46e2787..5e190d5eb9 100644--- a/apps/web/app/api/utm/[id]/route.ts+++ b/apps/web/app/api/utm/[id]/route.ts@@ -75,20 +75,30 @@ export const DELETE = withWorkspace(async ({ params, workspace }) => {const { id } = params;try {- const response = await prisma.utmTemplate.delete({+ const template = await prisma.utmTemplate.delete({where: {id,projectId: workspace.id,},+ include: {+ partnerGroup: true,+ },});- if (!response) {+ if (!template) {throw new DubApiError({code: "not_found",message: "UTM template not found.",});}+ if (template.partnerGroup) {+ throw new DubApiError({+ code: "conflict",+ message: "Cannot delete a template that is associated with a group.",+ });+ }+return NextResponse.json({ id });} catch (error) {if (error.code === "P2025") {