Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions apps/web/lib/partnerstack/import-commissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,15 @@ async function createCommission({

const customer = await prisma.customer.findFirst({
where: {
projectId: workspaceId,
OR: [
{
projectId: workspaceId,
email: commission.customer.email,
},
{
projectId: workspaceId,
externalId: commission.customer.external_key,
},
{ email: commission.customer.email },
{ externalId: commission.customer.external_key },
],
},
include: {
link: true,
},
orderBy: {
id: "asc",
},
});

if (!customer) {
Expand All @@ -152,15 +144,13 @@ async function createCommission({
const trackedCommission = await prisma.commission.findFirst({
where: {
programId,
type: "sale",
customer: {
id: customer.id,
},
amount: commission.transaction.amount,
createdAt: {
gte: new Date(chargedAt.getTime() - 60 * 60 * 1000), // 1 hour before
lte: new Date(chargedAt.getTime() + 60 * 60 * 1000), // 1 hour after
},
customerId: customer.id,
type: "sale",
amount: commission.transaction.amount,
},
});

Expand Down
10 changes: 5 additions & 5 deletions apps/web/lib/rewardful/import-commissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ async function createCommission({
const trackedCommission = await prisma.commission.findFirst({
where: {
programId: program.id,
type: "sale",
customer: {
stripeCustomerId: sale.referral.stripe_customer_id,
},
amount: sale.sale_amount_cents,
createdAt: {
gte: new Date(chargedAt.getTime() - 60 * 60 * 1000), // 1 hour before
lte: new Date(chargedAt.getTime() + 60 * 60 * 1000), // 1 hour after
},
customer: {
stripeCustomerId: sale.referral.stripe_customer_id,
},
type: "sale",
amount: sale.sale_amount_cents,
},
});

Expand Down
11 changes: 3 additions & 8 deletions apps/web/lib/tolt/import-commissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ async function createCommission({
include: {
link: true,
},
orderBy: {
id: "asc",
},
});

if (!customerFound) {
Expand All @@ -182,15 +179,13 @@ async function createCommission({
const trackedCommission = await prisma.commission.findFirst({
where: {
programId,
type: "sale",
customer: {
id: customerFound.id,
},
amount: Number(sale.amount),
createdAt: {
gte: new Date(chargedAt.getTime() - 60 * 60 * 1000), // 1 hour before
lte: new Date(chargedAt.getTime() + 60 * 60 * 1000), // 1 hour after
},
customerId: customerFound.id,
type: "sale",
amount: Number(sale.amount),
},
});

Expand Down