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

Kiran K73e3a1f5a700
diff --git a/apps/web/lib/actions/partners/create-commission.ts b/apps/web/lib/actions/partners/create-commission.ts
index a055f6f23d..5b82493f89 100644
--- a/apps/web/lib/actions/partners/create-commission.ts
+++ b/apps/web/lib/actions/partners/create-commission.ts
@@ -36,10 +36,20 @@ export const createCommissionAction = authActionClient
const programId = getDefaultProgramIdOrThrow(workspace);
- const { partner, links } = await getProgramEnrollmentOrThrow({
- programId,
- partnerId,
- });
+ const [{ partner, links }, customer] = await Promise.all([
+ getProgramEnrollmentOrThrow({
+ programId,
+ partnerId,
+ }),
+
+ customerId
+ ? prisma.customer.findUniqueOrThrow({
+ where: {
+ id: customerId,
+ },
+ })
+ : Promise.resolve(null),
+ ]);
// Create a custom commission
if (!linkId) {
@@ -56,16 +66,10 @@ export const createCommissionAction = authActionClient
}
// Create a lead or sale commission
- if (!customerId) {
- throw new Error("Customer ID is required.");
+ if (!customerId || !customer) {
+ throw new Error("Customer not found.");
}
- const customer = await prisma.customer.findUniqueOrThrow({
- where: {
- id: customerId,
- },
- });
-
if (customer.projectId !== workspace.id) {
throw new Error(`Customer ${customerId} not found.`);
}