The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add includeDefaultDiscount
Kiran Kb2beaf6c3af6
diff --git a/apps/web/app/api/partner-profile/programs/invites/route.ts b/apps/web/app/api/partner-profile/programs/invites/route.tsindex c5a6b73836..c7d5ea4f35 100644--- a/apps/web/app/api/partner-profile/programs/invites/route.ts+++ b/apps/web/app/api/partner-profile/programs/invites/route.ts@@ -15,7 +15,7 @@ export const GET = withPartnerProfile(async ({ session }) => {},});- // no need to consider the partner-specific rewards here, as the invite is still pending there is no programEnrollment+ // no need to consider the partner-specific rewards/discounts here, as the invite is still pending there is no programEnrollmentconst [programWideRewards, programWideDiscounts] = await Promise.all([prisma.reward.findMany({where: {diff --git a/apps/web/app/api/programs/[programId]/discounts/partners/route.ts b/apps/web/app/api/programs/[programId]/discounts/partners/route.tsindex 4bf1a61353..e02b616de4 100644--- a/apps/web/app/api/programs/[programId]/discounts/partners/route.ts+++ b/apps/web/app/api/programs/[programId]/discounts/partners/route.ts@@ -13,15 +13,17 @@ export const GET = withWorkspace(const { discountId, page, pageSize } =discountPartnersQuerySchema.parse(searchParams);- await getProgramOrThrow({- workspaceId: workspace.id,- programId,- });+ await Promise.all([+ getProgramOrThrow({+ workspaceId: workspace.id,+ programId,+ }),- await getDiscountOrThrow({- programId,- discountId,- });+ getDiscountOrThrow({+ programId,+ discountId,+ }),+ ]);const partners = await prisma.programEnrollment.findMany({where: {diff --git a/apps/web/app/api/programs/[programId]/route.ts b/apps/web/app/api/programs/[programId]/route.tsindex b2c46fd665..9f1d857c57 100644--- a/apps/web/app/api/programs/[programId]/route.ts+++ b/apps/web/app/api/programs/[programId]/route.ts@@ -10,7 +10,7 @@ export const GET = withWorkspace(async ({ workspace, params }) => {programId: params.programId,},{- includeDiscounts: true,+ includeDefaultDiscount: true,includeDefaultReward: true,},);diff --git a/apps/web/lib/api/programs/get-program-or-throw.ts b/apps/web/lib/api/programs/get-program-or-throw.tsindex ec548645eb..b2dc9c0129 100644--- a/apps/web/lib/api/programs/get-program-or-throw.ts+++ b/apps/web/lib/api/programs/get-program-or-throw.ts@@ -1,6 +1,5 @@-import { RewardProps } from "@/lib/types";+import { DiscountProps, ProgramProps, RewardProps } from "@/lib/types";import { ProgramSchema } from "@/lib/zod/schemas/programs";-import { RewardSchema } from "@/lib/zod/schemas/rewards";import { prisma } from "@dub/prisma";import { DubApiError } from "../errors";import { getRewardOrThrow } from "../partners/get-reward-or-throw";@@ -14,30 +13,30 @@ export const getProgramOrThrow = async (programId: string;},{- includeDiscounts = false,+ includeDefaultDiscount = false,includeDefaultReward = false,}: {- includeDiscounts?: boolean;+ includeDefaultDiscount?: boolean;includeDefaultReward?: boolean;} = {},) => {- const program = await prisma.program.findUnique({+ const program = (await prisma.program.findUnique({where: {id: programId,workspaceId,},- ...(includeDiscounts++ ...(includeDefaultDiscount? {include: {- discounts: {- orderBy: {- createdAt: "asc",- },- },+ defaultDiscount: true,},}: {}),- });+ })) as (ProgramProps & { defaultDiscount: DiscountProps | null }) | null;++ // TODO:+ // Add a new relation (defaultReward) to fetch the default rewardif (!program) {throw new DubApiError({@@ -53,12 +52,15 @@ export const getProgramOrThrow = async (rewardId: program.defaultRewardId,programId,});-- defaultReward = RewardSchema.parse(defaultReward);}return ProgramSchema.parse({...program,- ...(defaultReward ? { rewards: [defaultReward] } : {}),+ ...(includeDefaultReward && defaultReward+ ? { rewards: [defaultReward] }+ : {}),+ ...(includeDefaultDiscount && program.defaultDiscount+ ? { discounts: [program.defaultDiscount] }+ : {}),});};