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.

add workspace ID to linkschema

Steven Tey683d845cc85d
diff --git a/apps/web/app/api/links/route.ts b/apps/web/app/api/links/route.ts
index 9f551e6e98..cfbd220413 100644
--- a/apps/web/app/api/links/route.ts
+++ b/apps/web/app/api/links/route.ts
@@ -26,7 +26,7 @@ export const GET = withAuth(async ({ headers, searchParams, workspace }) => {
} = getLinksQuerySchema.parse(searchParams);
const response = await getLinksForWorkspace({
- projectId: workspace.id,
+ workspaceId: workspace.id,
domain,
tagId,
tagIds,
@@ -37,6 +37,7 @@ export const GET = withAuth(async ({ headers, searchParams, workspace }) => {
showArchived,
withTags,
});
+ console.log(response);
return NextResponse.json(response, {
headers,
});
diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.ts
index 73a2130beb..ace6dc6a86 100644
--- a/apps/web/lib/api/links.ts
+++ b/apps/web/lib/api/links.ts
@@ -35,7 +35,7 @@ import {
import z from "../zod";
export async function getLinksForWorkspace({
- projectId,
+ workspaceId,
domain,
tagId,
tagIds,
@@ -46,13 +46,13 @@ export async function getLinksForWorkspace({
showArchived,
withTags,
}: Omit<z.infer<typeof getLinksQuerySchema>, "projectSlug"> & {
- projectId: string;
+ workspaceId: string;
}) {
const combinedTagIds = combineTagIds({ tagId, tagIds });
const links = await prisma.link.findMany({
where: {
- projectId,
+ projectId: workspaceId,
archived: showArchived ? undefined : false,
...(domain && { domain }),
...(search && {
@@ -112,6 +112,7 @@ export async function getLinksForWorkspace({
tags,
shortLink,
qrCode: `https://api.dub.co/qr?url=${shortLink}`,
+ workspaceId: `ws_${link.projectId}`,
};
});
}
@@ -585,6 +586,7 @@ export async function addLink(link: LinkWithTagIdsProps) {
tags,
shortLink,
qrCode: `https://api.dub.co/qr?url=${shortLink}`,
+ workspaceId: `ws_${response.projectId}`,
};
}
@@ -656,6 +658,7 @@ export async function bulkCreateLinks({
tagId: tags?.[0]?.id ?? null, // backwards compatibility
tags,
qrCode: `https://api.dub.co/qr?url=${shortLink}`,
+ workspaceId: `ws_${link.projectId}`,
};
});
}
@@ -823,6 +826,7 @@ export async function editLink({
tags,
shortLink,
qrCode: `https://api.dub.co/qr?url=${shortLink}`,
+ workspaceId: `ws_${response.projectId}`,
};
}
diff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.ts
index 6eb254ed65..ae2271d03c 100644
--- a/apps/web/lib/zod/schemas/links.ts
+++ b/apps/web/lib/zod/schemas/links.ts
@@ -331,7 +331,7 @@ export const LinkSchema = z
userId: z
.string()
.describe("The user ID of the creator of the short link."),
- projectId: z.string().describe("The workspace ID of the short link."),
+ workspaceId: z.string().describe("The workspace ID of the short link."),
clicks: z
.number()
.default(0)
@@ -346,5 +346,11 @@ export const LinkSchema = z
updatedAt: z
.string()
.describe("The date and time when the short link was last updated."),
+ projectId: z
+ .string()
+ .describe(
+ "[DEPRECATED (use workspaceId instead)]: The project ID of the short link.",
+ )
+ .openapi({ deprecated: true }),
})
.openapi({ title: "Link" });