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-sale.ts

Kiran K27ae477ed93d
diff --git a/apps/web/lib/integrations/shopify/create-sale.ts b/apps/web/lib/integrations/shopify/create-sale.ts
index f3f544cb7c..68286aed76 100644
--- a/apps/web/lib/integrations/shopify/create-sale.ts
+++ b/apps/web/lib/integrations/shopify/create-sale.ts
@@ -130,74 +130,57 @@ export async function createShopifySale({
});
if (reward) {
- let eligibleForCommission = true;
-
- if (reward.maxDuration === 0) {
- const commissionCount = await prisma.commission.count({
- where: {
- type: "sale",
- customerId: customer.id,
- },
- });
-
- if (commissionCount > 0) {
- eligibleForCommission = false;
- }
- }
-
- if (eligibleForCommission) {
- const earnings = calculateSaleEarnings({
- reward,
- sale: {
- quantity: 1,
- amount: saleData.amount,
- },
- });
-
- await prisma.commission.create({
- data: {
- id: createId({ prefix: "cm_" }),
- programId: link.programId,
- linkId: link.id,
- partnerId: link.partnerId,
- eventId: saleData.event_id,
- customerId: customer.id,
- quantity: 1,
- type: "sale",
- amount,
- earnings,
- invoiceId,
- currency,
- },
- });
-
- waitUntil(
- (async () => {
- const program = await prisma.program.findUniqueOrThrow({
- where: {
- id: link.programId!,
- },
- select: {
- id: true,
- name: true,
- logo: true,
- },
- });
-
- await notifyPartnerSale({
- program,
- partner: {
- id: link.partnerId!,
- referralLink: link.shortLink,
- },
- sale: {
- amount: saleData.amount,
- earnings,
- },
- });
- })(),
- );
- }
+ const earnings = calculateSaleEarnings({
+ reward,
+ sale: {
+ quantity: 1,
+ amount: saleData.amount,
+ },
+ });
+
+ await prisma.commission.create({
+ data: {
+ id: createId({ prefix: "cm_" }),
+ programId: link.programId,
+ linkId: link.id,
+ partnerId: link.partnerId,
+ eventId: saleData.event_id,
+ customerId: customer.id,
+ quantity: 1,
+ type: "sale",
+ amount,
+ earnings,
+ invoiceId,
+ currency,
+ },
+ });
+
+ waitUntil(
+ (async () => {
+ const program = await prisma.program.findUniqueOrThrow({
+ where: {
+ id: link.programId!,
+ },
+ select: {
+ id: true,
+ name: true,
+ logo: true,
+ },
+ });
+
+ await notifyPartnerSale({
+ program,
+ partner: {
+ id: link.partnerId!,
+ referralLink: link.shortLink,
+ },
+ sale: {
+ amount: saleData.amount,
+ earnings,
+ },
+ });
+ })(),
+ );
}
}
}