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.

account for null referral.customer

Steven Tey2bfb72268337
diff --git a/apps/web/lib/rewardful/api.ts b/apps/web/lib/rewardful/api.ts
index eebcdd2091..0c35f360c7 100644
--- a/apps/web/lib/rewardful/api.ts
+++ b/apps/web/lib/rewardful/api.ts
@@ -4,6 +4,7 @@ import {
RewardfulCampaign,
RewardfulCommission,
RewardfulCoupon,
+ RewardfulCustomer,
RewardfulReferral,
} from "./types";
@@ -75,11 +76,12 @@ export class RewardfulApi {
searchParams.append("limit", REWARDFUL_PAGE_LIMIT.toString());
const { data } = await this.fetch<{
- data: Omit<RewardfulReferral, "id"> & { id: string | null }[];
+ data: Omit<RewardfulReferral, "customer"> &
+ { customer: RewardfulCustomer | null }[];
}>(`${this.baseUrl}/referrals?${searchParams.toString()}`);
- // for some reason the id can be null, so we need to filter out those referrals before returning the data
- const filteredData = data.filter((referral) => referral.id !== null);
+ // for some reason the customer can be null, so we need to filter out those referrals before returning the data
+ const filteredData = data.filter((referral) => referral.customer !== null);
return filteredData as RewardfulReferral[];
}
diff --git a/apps/web/lib/rewardful/import-customers.ts b/apps/web/lib/rewardful/import-customers.ts
index 2b6adefd8f..6e8e4b0f6e 100644
--- a/apps/web/lib/rewardful/import-customers.ts
+++ b/apps/web/lib/rewardful/import-customers.ts
@@ -47,6 +47,7 @@ export async function importCustomers(payload: RewardfulImportPayload) {
(r) => r.stripe_customer_id && r.stripe_customer_id.startsWith("cus_"),
)
.map((r) => r.stripe_customer_id!);
+
const externalIds = referrals.map((r) => r.customer.id);
const existingCustomers = await prisma.customer.findMany({