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.

started refactoring pricing & /usage endpoint

Steven Tey560902ca82bc
diff --git a/lib/types.ts b/lib/types.ts
index f5140d74a2..31f57c29a1 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -17,10 +17,6 @@ export interface ProjectProps {
slug: string;
domain: string;
domainVerified: boolean;
- plan: string;
- usageLimit: number;
- stripeId?: string;
- lastBilled: Date;
}
export type DomainVerificationStatusProps =
diff --git a/pages/api/projects/[slug]/domains/[domain]/usage.ts b/pages/api/projects/[slug]/domains/[domain]/usage.ts
deleted file mode 100644
index cdd55432f5..0000000000
--- a/pages/api/projects/[slug]/domains/[domain]/usage.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { NextApiRequest, NextApiResponse } from "next";
-import { withProjectAuth } from "@/lib/auth";
-import { getUsage } from "@/lib/upstash";
-import { ProjectProps } from "@/lib/types";
-
-export default withProjectAuth(
- async (req: NextApiRequest, res: NextApiResponse, project: ProjectProps) => {
- // GET /api/projects/[slug]/domains/[domain]/usage – get project usage
- if (req.method === "GET") {
- const { domain } = req.query as { domain: string };
- const usage = await getUsage(
- domain,
- project.plan !== "free" ? project.lastBilled : null
- );
- return res.status(200).json(usage);
- } else {
- res.setHeader("Allow", ["GET"]);
- return res
- .status(405)
- .json({ error: `Method ${req.method} Not Allowed` });
- }
- }
-);
diff --git a/pages/api/projects/usage.ts b/pages/api/projects/usage.ts
new file mode 100644
index 0000000000..cd0db4a428
--- /dev/null
+++ b/pages/api/projects/usage.ts
@@ -0,0 +1,22 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { getSession } from "@/lib/auth";
+import { getUsage } from "@/lib/upstash";
+import { ProjectProps } from "@/lib/types";
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse,
+ project: ProjectProps
+) {
+ const session = await getSession(req, res);
+ if (!session?.user.id) return res.status(401).end("Unauthorized");
+
+ // GET /api/projects/usage – get a user's usage over all their projects
+ if (req.method === "GET") {
+ const usage = await getUsage();
+ return res.status(200).json(usage);
+ } else {
+ res.setHeader("Allow", ["GET"]);
+ return res.status(405).json({ error: `Method ${req.method} Not Allowed` });
+ }
+}
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 318dc93615..e922cfb8b2 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -18,6 +18,8 @@ model User {
email String? @unique
emailVerified DateTime?
image String?
+ stripeId String? @unique // Stripe customer ID
+ lastBilled DateTime?
accounts Account[]
sessions Session[]
projects ProjectUsers[]
@@ -64,10 +66,6 @@ model Project {
slug String @unique
domain String @unique
domainVerified Boolean @default(false)
- plan String @default("free")
- usageLimit Int @default(1000)
- stripeId String? @unique // Stripe customer ID
- lastBilled DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
users ProjectUsers[]