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 route.ts

Kiran K47f80ee28136
diff --git a/apps/web/app/api/utm/[id]/route.ts b/apps/web/app/api/utm/[id]/route.ts
index ebddd26359..df98de0500 100644
--- a/apps/web/app/api/utm/[id]/route.ts
+++ b/apps/web/app/api/utm/[id]/route.ts
@@ -73,42 +73,38 @@ export const PATCH = withWorkspace(
export const DELETE = withWorkspace(
async ({ params, workspace }) => {
const { id } = params;
- try {
- const template = await prisma.utmTemplate.delete({
- where: {
- id,
- projectId: workspace.id,
- },
- include: {
- partnerGroup: true,
- },
- });
-
- if (!template) {
- throw new DubApiError({
- code: "not_found",
- message: "UTM template not found.",
- });
- }
- if (template.partnerGroup) {
- throw new DubApiError({
- code: "conflict",
- message: `This template is linked to the partner group "${template.partnerGroup.name}" and cannot be deleted.`,
- });
- }
+ const template = await prisma.utmTemplate.findUnique({
+ where: {
+ id,
+ projectId: workspace.id,
+ },
+ include: {
+ partnerGroup: true,
+ },
+ });
- return NextResponse.json({ id });
- } catch (error) {
- if (error.code === "P2025") {
- throw new DubApiError({
- code: "not_found",
- message: "UTM template not found.",
- });
- }
+ if (!template) {
+ throw new DubApiError({
+ code: "not_found",
+ message: "UTM template not found.",
+ });
+ }
- throw error;
+ if (template.partnerGroup) {
+ throw new DubApiError({
+ code: "conflict",
+ message: `This template is linked to the partner group "${template.partnerGroup.name}" and cannot be deleted.`,
+ });
}
+
+ await prisma.utmTemplate.delete({
+ where: {
+ id: template.id,
+ },
+ });
+
+ return NextResponse.json({ id });
},
{
requiredPermissions: ["links.write"],