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

Kiran K4c39d89f672a
diff --git a/apps/web/lib/partners/create-partner-commission.ts b/apps/web/lib/partners/create-partner-commission.ts
index f532a8a59c..7667b0552c 100644
--- a/apps/web/lib/partners/create-partner-commission.ts
+++ b/apps/web/lib/partners/create-partner-commission.ts
@@ -93,9 +93,38 @@ export const createPartnerCommission = async ({
orderBy: {
createdAt: "asc",
},
+ select: {
+ rewardId: true,
+ status: true,
+ createdAt: true,
+ },
});
if (firstCommission) {
+ // the partner reward has been changed since the first commission was created
+ // make sure the new reward has the same max duration as the original reward
+ if (
+ firstCommission.rewardId &&
+ firstCommission.rewardId !== reward.id
+ ) {
+ const originalReward = await prisma.reward.findUnique({
+ where: {
+ id: firstCommission.rewardId,
+ },
+ select: {
+ id: true,
+ maxDuration: true,
+ },
+ });
+
+ if (originalReward && originalReward.maxDuration === 0) {
+ console.log(
+ `Partner ${partnerId} is only eligible for first-sale commissions based on the original reward ${originalReward.id}, skipping commission creation...`,
+ );
+ return;
+ }
+ }
+
// for reward types with a max duration, we need to check if the first commission is within the max duration
// if its beyond the max duration, we should not create a new commission
if (typeof reward?.maxDuration === "number") {