The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
updated project link count endpoint
Steven Tey99de5d7b036a
diff --git a/components/app/project-card.tsx b/components/app/project-card.tsxindex f95a0b6b2d..dc790ce7a5 100644--- a/components/app/project-card.tsx+++ b/components/app/project-card.tsx@@ -18,7 +18,7 @@ export default function ProjectCard({domainVerified,}: ProjectProps) {const { data: count } = useSWR<number>(- `/api/projects/${slug}/domains/${domain}/links/count`,+ `/api/projects/${slug}/links/count`,fetcher,);return (diff --git a/lib/api/links.ts b/lib/api/links.tsindex 6a2c446dd1..0debd3d182 100644--- a/lib/api/links.ts+++ b/lib/api/links.ts@@ -40,15 +40,6 @@ export async function getLinksForProject({});}-export async function getLinkCountForProject(domain: string) {- return await prisma.link.count({- where: {- domain,- archived: false,- },- });-}-export async function getRandomKey(domain: string): Promise<string> {/* recursively get random key till it gets one that's avaialble */const key = nanoid();diff --git a/pages/api/projects/[slug]/links/count.ts b/pages/api/projects/[slug]/links/count.tsindex 57f5272aa3..0602084802 100644--- a/pages/api/projects/[slug]/links/count.ts+++ b/pages/api/projects/[slug]/links/count.ts@@ -1,16 +1,17 @@import { NextApiRequest, NextApiResponse } from "next";-import { getLinkCountForProject } from "@/lib/api/links";import { withProjectAuth } from "@/lib/auth";+import { ProjectProps } from "@/lib/types";export default withProjectAuth(- async (req: NextApiRequest, res: NextApiResponse) => {+ async (req: NextApiRequest, res: NextApiResponse, project: ProjectProps) => {// GET /api/projects/[slug]/domains/[domain]/links/count – count the number of links for a projectif (req.method === "GET") {- const { domain } = req.query as { domain: string };- if (!domain) {- return res.status(400).json({ error: "Missing domain" });- }- const count = await getLinkCountForProject(domain);+ const count = await prisma.link.count({+ where: {+ projectId: project.id,+ archived: false,+ },+ });return res.status(200).json(count);} else {res.setHeader("Allow", ["GET"]);diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 6bca891ba8..c1a52ad34a 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -17,10 +17,13 @@ model User {email String? @uniqueemailVerified DateTime?image String?++ // we need to move all 4 of these over to project levelstripeId String? @unique // Stripe customer IDusage Int @default(0)usageLimit Int @default(1000)billingCycleStart Int? // day of the month when the billing cycle starts+accounts Account[]sessions Session[]projects ProjectUsers[]@@ -95,6 +98,7 @@ model Domain {updatedAt DateTime @updatedAtproject Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)projectId String?+ primary Boolean @default(false)links Link[]}