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.

remove maxAmount

Steven Tey4ada1982d426
diff --git a/apps/web/lib/partners/create-partner-commission.ts b/apps/web/lib/partners/create-partner-commission.ts
index 18aa4340f3..c1f04909ed 100644
--- a/apps/web/lib/partners/create-partner-commission.ts
+++ b/apps/web/lib/partners/create-partner-commission.ts
@@ -90,7 +90,7 @@ export const createPartnerCommission = async ({
if (event === "click") {
earnings = reward.amount * quantity;
- // for lead and sale events, we need to check the first time this partner-customer combination was recorded (for deduplication)
+ // for lead and sale events, we need to check if this partner-customer combination was recorded already (for deduplication)
// for sale rewards specifically, we also need to check:
// 1. if the partner has reached the max duration for the reward (if applicable)
// 2. if the previous commission were marked as fraud or canceled
@@ -195,37 +195,6 @@ export const createPartnerCommission = async ({
});
}
}
-
- // handle rewards with max reward amount limit
- if (reward.maxAmount) {
- const totalRewards = await prisma.commission.aggregate({
- where: {
- earnings: {
- gt: 0,
- },
- programId,
- partnerId,
- status: {
- in: ["pending", "processed", "paid"],
- },
- type: event,
- },
- _sum: {
- earnings: true,
- },
- });
-
- const totalEarnings = totalRewards._sum.earnings || 0;
- if (totalEarnings >= reward.maxAmount) {
- console.log(
- `Partner ${partnerId} has reached max reward amount for ${event} event, skipping commission creation...`,
- );
- return;
- }
-
- const remainingRewardAmount = reward.maxAmount - totalEarnings;
- earnings = Math.max(0, Math.min(earnings, remainingRewardAmount));
- }
}
try {
diff --git a/apps/web/lib/zod/schemas/rewards.ts b/apps/web/lib/zod/schemas/rewards.ts
index f7376ec4f0..7bae3af13a 100644
--- a/apps/web/lib/zod/schemas/rewards.ts
+++ b/apps/web/lib/zod/schemas/rewards.ts
@@ -139,7 +139,6 @@ export const RewardSchema = z.object({
type: z.nativeEnum(RewardStructure),
amount: z.number(),
maxDuration: z.number().nullish(),
- maxAmount: z.number().nullish(),
modifiers: z.any().nullish(), // TODO: Fix this
});
diff --git a/packages/prisma/schema/reward.prisma b/packages/prisma/schema/reward.prisma
index d17d62778f..b38c3b6ca1 100644
--- a/packages/prisma/schema/reward.prisma
+++ b/packages/prisma/schema/reward.prisma
@@ -17,7 +17,6 @@ model Reward {
type RewardStructure @default(percentage)
amount Int @default(0)
maxDuration Int? // in months (0 -> not recurring, null -> infinite)
- maxAmount Int? // how much a partner can receive payouts (in cents)
modifiers Json? @db.Json
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt