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 partnerstack

Kiran Keb9f3b8a7743
diff --git a/apps/web/lib/partnerstack/import-links.ts b/apps/web/lib/partnerstack/import-links.ts
index 7cdfb15656..5200200702 100644
--- a/apps/web/lib/partnerstack/import-links.ts
+++ b/apps/web/lib/partnerstack/import-links.ts
@@ -16,6 +16,11 @@ export async function importLinks(payload: PartnerStackImportPayload) {
},
include: {
workspace: true,
+ groups: {
+ include: {
+ partnerGroupDefaultLinks: true,
+ },
+ },
},
});
@@ -28,6 +33,9 @@ export async function importLinks(payload: PartnerStackImportPayload) {
secretKey,
});
+ // Create a map of group Id to group
+ const groupsById = new Map(program.groups.map((group) => [group.id, group]));
+
let hasMore = true;
let currentStartingAfter = startingAfter;
@@ -37,6 +45,7 @@ export async function importLinks(payload: PartnerStackImportPayload) {
},
select: {
id: true,
+ groupId: true,
partner: {
select: {
id: true,
@@ -60,7 +69,7 @@ export async function importLinks(payload: PartnerStackImportPayload) {
currentStartingAfter = enrollments[enrollments.length - 1].id;
}
- for (const { partner } of enrollments) {
+ for (const { partner, groupId } of enrollments) {
if (!partner.email) {
console.log("Partner has no email. Skipping the link import.");
continue;
@@ -76,8 +85,10 @@ export async function importLinks(payload: PartnerStackImportPayload) {
continue;
}
+ const partnerGroup = groupsById.get(groupId!);
+
await Promise.allSettled(
- links.map(async (link) =>
+ links.map(async (link, idx) =>
createPartnerLink({
workspace: program.workspace as WorkspaceProps,
program,
@@ -85,6 +96,8 @@ export async function importLinks(payload: PartnerStackImportPayload) {
link,
userId,
importId,
+ partnerGroupDefaultLinkId:
+ partnerGroup?.partnerGroupDefaultLinks[idx]?.id ?? null,
}),
),
);
@@ -111,6 +124,7 @@ async function createPartnerLink({
link,
userId,
importId,
+ partnerGroupDefaultLinkId,
}: {
workspace: WorkspaceProps;
program: ProgramProps;
@@ -118,6 +132,7 @@ async function createPartnerLink({
link: PartnerStackLink;
userId: string;
importId: string;
+ partnerGroupDefaultLinkId: string | null;
}) {
const commonImportLogInputs = {
workspace_id: workspace.id,
@@ -171,6 +186,7 @@ async function createPartnerLink({
domain: program.domain!,
url: link.url,
key,
+ partnerGroupDefaultLinkId,
},
userId,
});