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.

simplify partner-profile/links endpoints

Steven Teyf50fba7b6450
diff --git a/apps/web/app/api/partner-profile/programs/[programId]/links/[linkId]/route.ts b/apps/web/app/api/partner-profile/programs/[programId]/links/[linkId]/route.ts
index 0d980cdcab..c06c389da8 100644
--- a/apps/web/app/api/partner-profile/programs/[programId]/links/[linkId]/route.ts
+++ b/apps/web/app/api/partner-profile/programs/[programId]/links/[linkId]/route.ts
@@ -5,7 +5,6 @@ import { parseRequestBody } from "@/lib/api/utils";
import { withPartnerProfile } from "@/lib/auth/partner";
import { NewLinkProps } from "@/lib/types";
import { createPartnerLinkSchema } from "@/lib/zod/schemas/partners";
-import { prisma } from "@dub/prisma";
import { getApexDomain } from "@dub/utils";
import { NextResponse } from "next/server";
@@ -47,23 +46,6 @@ export const PATCH = withPartnerProfile(
});
}
- const workspace = await prisma.project.findUnique({
- select: {
- id: true,
- plan: true,
- },
- where: {
- id: program.workspaceId,
- },
- });
-
- if (!workspace) {
- throw new DubApiError({
- code: "bad_request",
- message: "Workspace not found for program.",
- });
- }
-
// if domain and key are the same, we don't need to check if the key exists
const skipKeyChecks = link.key.toLowerCase() === key?.toLowerCase();
@@ -86,7 +68,10 @@ export const PATCH = withPartnerProfile(
url: url || program.url,
comments,
},
- workspace: workspace as any,
+ workspace: {
+ id: program.workspaceId,
+ plan: "business",
+ },
userId: session.user.id,
skipKeyChecks,
skipFolderChecks: true, // can't be changed by the partner
diff --git a/apps/web/app/api/partner-profile/programs/[programId]/links/route.ts b/apps/web/app/api/partner-profile/programs/[programId]/links/route.ts
index ba131c6947..ee6a18f9d0 100644
--- a/apps/web/app/api/partner-profile/programs/[programId]/links/route.ts
+++ b/apps/web/app/api/partner-profile/programs/[programId]/links/route.ts
@@ -5,7 +5,6 @@ import { parseRequestBody } from "@/lib/api/utils";
import { withPartnerProfile } from "@/lib/auth/partner";
import { createPartnerLinkSchema } from "@/lib/zod/schemas/partners";
import { PartnerLinkSchema } from "@/lib/zod/schemas/programs";
-import { prisma } from "@dub/prisma";
import { getApexDomain } from "@dub/utils";
import { NextResponse } from "next/server";
@@ -55,23 +54,6 @@ export const POST = withPartnerProfile(
});
}
- const workspace = await prisma.project.findUnique({
- select: {
- id: true,
- plan: true,
- },
- where: {
- id: program.workspaceId,
- },
- });
-
- if (!workspace) {
- throw new DubApiError({
- code: "bad_request",
- message: "Workspace not found for program.",
- });
- }
-
const { link, error, code } = await processLink({
payload: {
domain: program.domain,
@@ -84,7 +66,10 @@ export const POST = withPartnerProfile(
comments,
trackConversion: true,
},
- workspace: workspace as any,
+ workspace: {
+ id: program.workspaceId,
+ plan: "business",
+ },
userId: session.user.id,
skipFolderChecks: true, // can't be changed by the partner
skipProgramChecks: true, // can't be changed by the partner
diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.ts
index 6a0d87f1ab..d97a38522e 100644
--- a/apps/web/lib/api/links/process-link.ts
+++ b/apps/web/lib/api/links/process-link.ts
@@ -33,7 +33,7 @@ export async function processLink<T extends Record<string, any>>({
skipProgramChecks = false, // only skip for when program is already validated
}: {
payload: NewLinkProps & T;
- workspace?: Pick<WorkspaceProps, "id" | "plan" | "flags">;
+ workspace?: Pick<WorkspaceProps, "id" | "plan">;
userId?: string;
bulk?: boolean;
skipKeyChecks?: boolean;