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.

update-process link

Kiran K542cde7551f5
diff --git a/apps/web/lib/api/links/create-link.ts b/apps/web/lib/api/links/create-link.ts
index 7552466bbb..efe2ffd1d7 100644
--- a/apps/web/lib/api/links/create-link.ts
+++ b/apps/web/lib/api/links/create-link.ts
@@ -31,6 +31,7 @@ export async function createLink(link: ProcessedLinkProps) {
proxy,
geo,
publicStats,
+ partnerId,
} = link;
const combinedTagIds = combineTagIds(link);
@@ -41,21 +42,6 @@ export async function createLink(link: ProcessedLinkProps) {
const { tagId, tagIds, tagNames, webhookIds, programId, tenantId, ...rest } =
link;
- const partner =
- programId && tenantId
- ? await prisma.programEnrollment.findUnique({
- where: {
- tenantId_programId: {
- tenantId,
- programId,
- },
- },
- select: {
- partnerId: true,
- },
- })
- : null;
-
const response = await prisma.link.create({
data: {
...rest,
@@ -75,6 +61,7 @@ export async function createLink(link: ProcessedLinkProps) {
geo: geo || Prisma.JsonNull,
programId,
tenantId,
+ partnerId,
// Associate tags by tagNames
...(tagNames?.length &&
@@ -129,11 +116,6 @@ export async function createLink(link: ProcessedLinkProps) {
},
},
}),
-
- // Partner link
- ...(partner && {
- partnerId: partner.partnerId,
- }),
},
include: {
...includeTags,
diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.ts
index c4adc75098..c5c2b236a4 100644
--- a/apps/web/lib/api/links/process-link.ts
+++ b/apps/web/lib/api/links/process-link.ts
@@ -67,6 +67,7 @@ export async function processLink<T extends Record<string, any>>({
externalId,
programId,
webhookIds,
+ tenantId,
} = payload;
let expiresAt: string | Date | null | undefined = payload.expiresAt;
@@ -449,6 +450,21 @@ export async function processLink<T extends Record<string, any>>({
}
}
+ const partner =
+ programId && tenantId
+ ? await prisma.programEnrollment.findUnique({
+ where: {
+ tenantId_programId: {
+ tenantId,
+ programId,
+ },
+ },
+ select: {
+ partnerId: true,
+ },
+ })
+ : null;
+
// remove polyfill attributes from payload
delete payload["shortLink"];
delete payload["qrCode"];
@@ -475,6 +491,9 @@ export async function processLink<T extends Record<string, any>>({
...(webhookIds && {
webhookIds,
}),
+ ...(partner && {
+ partnerId: partner.partnerId,
+ }),
},
error: null,
};
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 3bcb770b12..1615ab8386 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -225,6 +225,7 @@ export type ProcessedLinkProps = Omit<NewLinkProps, ProcessedLinkOverrides> &
Pick<LinkProps, ProcessedLinkOverrides> & { userId?: LinkProps["userId"] } & {
createdAt?: Date;
id?: string;
+ partnerId?: string;
};
export const plans = [