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.

fix programEnrollment discount

Steven Tey5700ba598d0a
diff --git a/apps/web/app/app.dub.co/embed/utils.ts b/apps/web/app/app.dub.co/embed/utils.ts
index 1a721e89ee..b554a7787c 100644
--- a/apps/web/app/app.dub.co/embed/utils.ts
+++ b/apps/web/app/app.dub.co/embed/utils.ts
@@ -15,7 +15,11 @@ export const getEmbedData = async (token: string) => {
id: linkId,
},
include: {
- program: true,
+ program: {
+ include: {
+ discounts: true,
+ },
+ },
programEnrollment: {
select: {
discount: true,
@@ -37,7 +41,9 @@ export const getEmbedData = async (token: string) => {
return {
program,
link,
- discount: DiscountSchema.parse(programEnrollment?.discount),
+ discount: DiscountSchema.parse(
+ programEnrollment?.discount || program.discounts?.[0],
+ ),
earnings:
(program.commissionType === "percentage" ? link.saleAmount : link.sales) *
(program.commissionAmount / 100),
diff --git a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/page-client.tsx b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/page-client.tsx
index 04adb27bc9..3ddbd1a3b7 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/page-client.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/page-client.tsx
@@ -71,7 +71,7 @@ export default function ProgramPageClient() {
{program ? (
<ProgramCommissionDescription
program={program}
- discount={programEnrollment?.discount}
+ discount={programEnrollment?.discount || program.discounts?.[0]}
/>
) : (
<div className="h-7 w-5/6 animate-pulse rounded-md bg-neutral-200" />
diff --git a/apps/web/lib/api/programs/get-program-enrollment-or-throw.ts b/apps/web/lib/api/programs/get-program-enrollment-or-throw.ts
index 57f5e115c9..3fa7340923 100644
--- a/apps/web/lib/api/programs/get-program-enrollment-or-throw.ts
+++ b/apps/web/lib/api/programs/get-program-enrollment-or-throw.ts
@@ -1,4 +1,5 @@
import { prisma } from "@dub/prisma";
+import { Prisma } from "@dub/prisma/client";
import { DubApiError } from "../errors";
export async function getProgramEnrollmentOrThrow({
@@ -8,6 +9,16 @@ export async function getProgramEnrollmentOrThrow({
partnerId: string;
programId: string;
}) {
+ const include: Prisma.ProgramEnrollmentInclude = {
+ program: {
+ include: {
+ discounts: true,
+ },
+ },
+ link: true,
+ discount: true,
+ };
+
const programEnrollment = programId.startsWith("prog_")
? await prisma.programEnrollment.findUnique({
where: {
@@ -16,11 +27,7 @@ export async function getProgramEnrollmentOrThrow({
programId,
},
},
- include: {
- program: true,
- link: true,
- discount: true,
- },
+ include,
})
: await prisma.programEnrollment.findFirst({
where: {
@@ -29,11 +36,7 @@ export async function getProgramEnrollmentOrThrow({
slug: programId,
},
},
- include: {
- program: true,
- link: true,
- discount: true,
- },
+ include,
});
if (!programEnrollment || !programEnrollment.program) {