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.

fixes to customer import

Kiran K005bb7063374
diff --git a/apps/web/app/(ee)/api/cron/import/tolt/route.ts b/apps/web/app/(ee)/api/cron/import/tolt/route.ts
index 53f7339d91..73f9b5c097 100644
--- a/apps/web/app/(ee)/api/cron/import/tolt/route.ts
+++ b/apps/web/app/(ee)/api/cron/import/tolt/route.ts
@@ -15,7 +15,6 @@ const schema = z.object({
action: importSteps,
programId: z.string(),
startingAfter: z.string().optional(),
- page: z.number().optional(),
});
export async function POST(req: Request) {
@@ -39,12 +38,12 @@ export async function POST(req: Request) {
case "import-referrals":
await importReferrals(payload);
break;
- case "update-stripe-customers":
- await updateStripeCustomers(payload);
- break;
case "import-commissions":
await importCommissions(payload);
break;
+ case "update-stripe-customers":
+ await updateStripeCustomers(payload);
+ break;
}
return NextResponse.json("OK");
diff --git a/apps/web/lib/tolt/import-commissions.ts b/apps/web/lib/tolt/import-commissions.ts
index 9999cca56d..becdc907fb 100644
--- a/apps/web/lib/tolt/import-commissions.ts
+++ b/apps/web/lib/tolt/import-commissions.ts
@@ -1,3 +1,5 @@
+import { sendEmail } from "@dub/email";
+import CampaignImported from "@dub/email/templates/campaign-imported";
import { prisma } from "@dub/prisma";
import { nanoid } from "@dub/utils";
import { CommissionStatus } from "@prisma/client";
@@ -70,39 +72,45 @@ export async function importCommissions({
action: "import-commissions",
startingAfter,
});
+
return;
}
- // await toltImporter.deleteCredentials(workspace.id);
+ await toltImporter.deleteCredentials(workspace.id);
- // const workspaceUser = await prisma.projectUsers.findUniqueOrThrow({
- // where: {
- // userId_projectId: {
- // userId,
- // projectId: workspace.id,
- // },
- // },
- // select: {
- // user: {
- // select: {
- // email: true,
- // },
- // },
- // },
- // });
+ const workspaceUser = await prisma.projectUsers.findUniqueOrThrow({
+ where: {
+ userId_projectId: {
+ userId,
+ projectId: workspace.id,
+ },
+ },
+ select: {
+ user: {
+ select: {
+ email: true,
+ },
+ },
+ },
+ });
- // if (workspaceUser && workspaceUser.user.email) {
- // await sendEmail({
- // email: workspaceUser.user.email,
- // subject: "Tolt program imported",
- // react: CampaignImported({
- // email: workspaceUser.user.email,
- // workspace,
- // program,
- // provider: "Tolt",
- // }),
- // });
- // }
+ if (workspaceUser && workspaceUser.user.email) {
+ await sendEmail({
+ email: workspaceUser.user.email,
+ subject: "Tolt program imported",
+ react: CampaignImported({
+ email: workspaceUser.user.email,
+ workspace,
+ program,
+ provider: "Tolt",
+ }),
+ });
+ }
+
+ await toltImporter.queue({
+ programId,
+ action: "update-stripe-customers",
+ });
}
// Backfill historical commissions
diff --git a/apps/web/lib/tolt/import-referrals.ts b/apps/web/lib/tolt/import-referrals.ts
index ac1b2f827c..db28794424 100644
--- a/apps/web/lib/tolt/import-referrals.ts
+++ b/apps/web/lib/tolt/import-referrals.ts
@@ -143,7 +143,7 @@ async function createReferral({
},
});
- if (customerFound) {
+ if (customerFound && customerFound.externalId !== customer.customer_id) {
console.log(
`A customer already exists with customer email, ${customer.email}`,
);