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 create-commission.ts

Steven Tey0a9e5bfeba76
diff --git a/apps/web/lib/actions/partners/create-commission.ts b/apps/web/lib/actions/partners/create-commission.ts
index f21fabbf67..debdf4429c 100644
--- a/apps/web/lib/actions/partners/create-commission.ts
+++ b/apps/web/lib/actions/partners/create-commission.ts
@@ -9,8 +9,6 @@ import { clickEventSchemaTB } from "@/lib/zod/schemas/clicks";
import { createCommissionSchema } from "@/lib/zod/schemas/commissions";
import { prisma } from "@dub/prisma";
import { nanoid } from "@dub/utils";
-import { getLinkOrThrow } from "../../api/links/get-link-or-throw";
-import { getProgramOrThrow } from "../../api/programs/get-program-or-throw";
import { authActionClient } from "../safe-action";
export const createCommissionAction = authActionClient
@@ -29,22 +27,11 @@ export const createCommissionAction = authActionClient
leadDate,
} = parsedInput;
- const [_, link, programEnrollment, customer] = await Promise.all([
- getProgramOrThrow({
- workspaceId: workspace.id,
- programId,
- }),
-
- getLinkOrThrow({
- workspaceId: workspace.id,
- linkId,
- }),
-
+ const [programEnrollment, customer] = await Promise.all([
getProgramEnrollmentOrThrow({
programId,
partnerId,
}),
-
prisma.customer.findUniqueOrThrow({
where: {
id: customerId,
@@ -52,7 +39,9 @@ export const createCommissionAction = authActionClient
}),
]);
- if (programEnrollment.program.workspaceId !== workspace.id) {
+ const { program, partner, links } = programEnrollment;
+
+ if (program.workspaceId !== workspace.id) {
throw new Error(`Program ${programId} not found.`);
}
@@ -60,6 +49,14 @@ export const createCommissionAction = authActionClient
throw new Error(`Customer ${customerId} not found.`);
}
+ const link = links.find((l) => l.id === linkId);
+
+ if (!link) {
+ throw new Error(
+ `Link ${linkId} does not belong to partner ${partner.email} (${partnerId}).`,
+ );
+ }
+
if (invoiceId) {
const commission = await prisma.commission.findUnique({
where: {