The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
improve prepareEarnings
Kiran K83334b807715
diff --git a/apps/web/app/api/stripe/integration/webhook/checkout-session-completed.ts b/apps/web/app/api/stripe/integration/webhook/checkout-session-completed.tsindex e2c36642bf..bc906e9b9d 100644--- a/apps/web/app/api/stripe/integration/webhook/checkout-session-completed.ts+++ b/apps/web/app/api/stripe/integration/webhook/checkout-session-completed.ts@@ -277,8 +277,8 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {const leadEarnings = clickEvent? prepareEarnings({- link,- customer,+ linkId: link.id,+ customerId: customer.id,program,partner,event: {@@ -289,8 +289,8 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {: null;const saleEarnings = prepareEarnings({- link,- customer,+ linkId: link.id,+ customerId: customer.id,program,partner,event: {diff --git a/apps/web/app/api/stripe/integration/webhook/customer-created.ts b/apps/web/app/api/stripe/integration/webhook/customer-created.tsindex 1df9d47bd5..d8fff6667a 100644--- a/apps/web/app/api/stripe/integration/webhook/customer-created.ts+++ b/apps/web/app/api/stripe/integration/webhook/customer-created.ts@@ -144,8 +144,8 @@ export async function customerCreated(event: Stripe.Event) {await prisma.earnings.create({data: prepareEarnings({- link,- customer,+ linkId: link.id,+ customerId: customer.id,program,partner,event: {diff --git a/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts b/apps/web/app/api/stripe/integration/webhook/invoice-paid.tsindex 4ddeee4e3c..e0d72042e1 100644--- a/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts+++ b/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts@@ -130,8 +130,8 @@ export async function invoicePaid(event: Stripe.Event) {});const earningsData = prepareEarnings({- link,- customer,+ linkId: link.id,+ customerId: customer.id,program,partner,event: {diff --git a/apps/web/app/api/track/lead/route.ts b/apps/web/app/api/track/lead/route.tsindex e0fa3fe3a4..6b93a99ea0 100644--- a/apps/web/app/api/track/lead/route.ts+++ b/apps/web/app/api/track/lead/route.ts@@ -143,8 +143,8 @@ export const POST = withWorkspaceEdge(await prismaEdge.earnings.create({data: prepareEarnings({- link,- customer,+ linkId: link.id,+ customerId: customer.id,program,partner,event: {diff --git a/apps/web/app/api/track/sale/route.ts b/apps/web/app/api/track/sale/route.tsindex 5a1daeb105..17cbc1730f 100644--- a/apps/web/app/api/track/sale/route.ts+++ b/apps/web/app/api/track/sale/route.ts@@ -143,8 +143,8 @@ export const POST = withWorkspaceEdge(});const earningsData = prepareEarnings({- link,- customer,+ linkId: link.id,+ customerId: customer.id,program,partner,event: {diff --git a/apps/web/lib/api/earnings/prepare-earnings.ts b/apps/web/lib/api/earnings/prepare-earnings.tsindex a4bc086020..437769277f 100644--- a/apps/web/lib/api/earnings/prepare-earnings.ts+++ b/apps/web/lib/api/earnings/prepare-earnings.ts@@ -1,7 +1,5 @@import {- Customer,EventType,- Link,Prisma,Program,ProgramEnrollment,@@ -9,11 +7,12 @@ import {import { calculateSaleEarnings } from "../sales/calculate-earnings";interface CreateEarnings {- link: Pick<Link, "id">;- customer?: Pick<Customer, "id">;program: Pick<Program, "id" | "commissionAmount" | "commissionType">;partner: Pick<ProgramEnrollment, "partnerId" | "commissionAmount">;+ linkId: string;+ customerId?: string;+event: {type: EventType;id: string;@@ -33,13 +32,13 @@ interface CreateEarnings {export const prepareEarnings = ({event,- link,- customer,+ linkId,+ customerId,program,partner,click,sale,-}: CreateEarnings) => {+}: CreateEarnings): Prisma.EarningsUncheckedCreateInput => {const amount = click?.amount || sale?.amount || 0;const invoiceId = sale?.invoiceId;const currency = sale?.currency;@@ -56,10 +55,10 @@ export const prepareEarnings = ({}): null;- const data: Prisma.EarningsUncheckedCreateInput = {+ return {eventId: event.id,type: event.type,- linkId: link.id,+ linkId,programId: program.id,partnerId: partner.partnerId,quantity,@@ -67,10 +66,6 @@ export const prepareEarnings = ({...(currency && { currency: currency.toLowerCase() }),...(earnings && { earnings }),...(invoiceId && { invoiceId }),- ...(customer && { customerId: customer.id }),+ ...(customerId && { customerId }),};-- console.info("Earnings", data);-- return data;};diff --git a/apps/web/lib/integrations/shopify/create-lead.ts b/apps/web/lib/integrations/shopify/create-lead.tsindex 538a92571b..65da8b3c91 100644--- a/apps/web/lib/integrations/shopify/create-lead.ts+++ b/apps/web/lib/integrations/shopify/create-lead.ts@@ -104,8 +104,8 @@ export async function createShopifyLead({await prisma.earnings.create({data: prepareEarnings({- link,- customer,+ linkId: link.id,+ customerId: customer.id,program,partner,event: {diff --git a/apps/web/lib/integrations/shopify/create-sale.ts b/apps/web/lib/integrations/shopify/create-sale.tsindex cd458348fc..40ed1e81c2 100644--- a/apps/web/lib/integrations/shopify/create-sale.ts+++ b/apps/web/lib/integrations/shopify/create-sale.ts@@ -137,8 +137,8 @@ export async function createShopifySale({});const earningsData = prepareEarnings({- link,- customer,+ linkId: link.id,+ customerId: customer.id,program,partner,event: {