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.

fix import crash when customer.id is null

Pedro Ladeira809b3b1e2e0a
diff --git a/apps/web/lib/rewardful/import-customers.ts b/apps/web/lib/rewardful/import-customers.ts
index a3268c7cfe..f31234f594 100644
--- a/apps/web/lib/rewardful/import-customers.ts
+++ b/apps/web/lib/rewardful/import-customers.ts
@@ -48,19 +48,31 @@ export async function importCustomers(payload: RewardfulImportPayload) {
)
.map((r) => r.stripe_customer_id!);
- const externalIds = referrals.map((r) => r.customer.id);
-
- const existingCustomers = await prisma.customer.findMany({
- where: {
- OR: [
- { stripeCustomerId: { in: stripeCustomerIds } },
- {
- projectId: workspace.id,
- externalId: { in: externalIds },
- },
- ],
- },
- });
+ // Rewardful can return a customer object with a null id.
+ const externalIds = referrals
+ .map((r) => r.customer.id)
+ .filter((id): id is string => Boolean(id));
+
+ const existingCustomers =
+ stripeCustomerIds.length === 0 && externalIds.length === 0
+ ? []
+ : await prisma.customer.findMany({
+ where: {
+ OR: [
+ ...(stripeCustomerIds.length > 0
+ ? [{ stripeCustomerId: { in: stripeCustomerIds } }]
+ : []),
+ ...(externalIds.length > 0
+ ? [
+ {
+ projectId: workspace.id,
+ externalId: { in: externalIds },
+ },
+ ]
+ : []),
+ ],
+ },
+ });
const referrralChunks = chunk(referrals, 10);
for (const referralChunk of referrralChunks) {
diff --git a/apps/web/lib/rewardful/types.ts b/apps/web/lib/rewardful/types.ts
index c60f702d40..3d6028b894 100644
--- a/apps/web/lib/rewardful/types.ts
+++ b/apps/web/lib/rewardful/types.ts
@@ -36,7 +36,7 @@ export interface RewardfulLink {
}
export interface RewardfulCustomer {
- id: string;
+ id: string | null;
name: string;
email: string;
platform: string;