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 groupsLimit

Kiran K1380b51ae74a
diff --git a/apps/web/app/(ee)/api/groups/count/route.ts b/apps/web/app/(ee)/api/groups/count/route.ts
index 5cb8c0fe08..89b53f2437 100644
--- a/apps/web/app/(ee)/api/groups/count/route.ts
+++ b/apps/web/app/(ee)/api/groups/count/route.ts
@@ -1,16 +1,36 @@
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
import { withWorkspace } from "@/lib/auth";
+import { getGroupsCountQuerySchema } from "@/lib/zod/schemas/groups";
+import { prisma } from "@dub/prisma";
import { NextResponse } from "next/server";
// GET /api/groups/count - get the count of groups for a program
export const GET = withWorkspace(
async ({ workspace, searchParams }) => {
const programId = getDefaultProgramIdOrThrow(workspace);
+ const { search } = getGroupsCountQuerySchema.parse(searchParams);
- // TODO:
- // Decide the filters we want to fetch the count by
+ const count = await prisma.partnerGroup.count({
+ where: {
+ programId,
+ ...(search && {
+ OR: [
+ {
+ name: {
+ contains: search,
+ },
+ },
+ {
+ slug: {
+ contains: search,
+ },
+ },
+ ],
+ }),
+ },
+ });
- return NextResponse.json(1);
+ return NextResponse.json(count);
},
{
requiredPlan: [
diff --git a/apps/web/app/(ee)/api/stripe/webhook/checkout-session-completed.ts b/apps/web/app/(ee)/api/stripe/webhook/checkout-session-completed.ts
index ab55baddbb..f76907b82c 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/checkout-session-completed.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/checkout-session-completed.ts
@@ -68,6 +68,7 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
aiLimit: plan.limits.ai!,
tagsLimit: plan.limits.tags!,
foldersLimit: plan.limits.folders!,
+ groupsLimit: plan.limits.groups!,
usersLimit: plan.limits.users!,
paymentFailedAt: null,
},
diff --git a/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-deleted.ts b/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-deleted.ts
index 12899ea1d0..5d52fd4baf 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-deleted.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-deleted.ts
@@ -103,6 +103,7 @@ export async function customerSubscriptionDeleted(event: Stripe.Event) {
aiLimit: FREE_PLAN.limits.ai!,
tagsLimit: FREE_PLAN.limits.tags!,
foldersLimit: FREE_PLAN.limits.folders!,
+ groupsLimit: FREE_PLAN.limits.groups!,
usersLimit: FREE_PLAN.limits.users!,
paymentFailedAt: null,
foldersUsage: 0,
diff --git a/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-updated.ts b/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-updated.ts
index 5f3d861cad..b7d783b110 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-updated.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-updated.ts
@@ -92,6 +92,7 @@ export async function customerSubscriptionUpdated(event: Stripe.Event) {
aiLimit: plan.limits.ai!,
tagsLimit: plan.limits.tags!,
foldersLimit: plan.limits.folders!,
+ groupsLimit: plan.limits.groups!,
usersLimit: plan.limits.users!,
paymentFailedAt: null,
...(shouldDeleteFolders && { foldersUsage: 0 }),
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx
index 72a33ed9b6..613c12a3cc 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx
@@ -49,6 +49,7 @@ export default function PlanUsage() {
domainsLimit,
foldersUsage,
foldersLimit,
+ groupsLimit,
tagsLimit,
usersLimit,
partnersEnabled,
diff --git a/apps/web/lib/api/errors.ts b/apps/web/lib/api/errors.ts
index e53d9e8839..717c086ebf 100644
--- a/apps/web/lib/api/errors.ts
+++ b/apps/web/lib/api/errors.ts
@@ -241,7 +241,8 @@ export const exceededLimitError = ({
| "tags"
| "users"
| "folders"
- | "payouts";
+ | "payouts"
+ | "groups";
}) => {
return `You've reached your ${
["links", "AI", "payouts"].includes(type) ? "monthly" : ""
diff --git a/apps/web/lib/zod/schemas/groups.ts b/apps/web/lib/zod/schemas/groups.ts
index aca315321e..417eaab7de 100644
--- a/apps/web/lib/zod/schemas/groups.ts
+++ b/apps/web/lib/zod/schemas/groups.ts
@@ -70,3 +70,7 @@ export const getGroupsQuerySchema = z
includeExpandedFields: booleanQuerySchema.optional(),
})
.merge(getPaginationQuerySchema({ pageSize: 100 }));
+
+export const getGroupsCountQuerySchema = z.object({
+ search: z.string().optional(),
+});
diff --git a/apps/web/lib/zod/schemas/workspaces.ts b/apps/web/lib/zod/schemas/workspaces.ts
index 71d8b94c4f..fec4b54fa6 100644
--- a/apps/web/lib/zod/schemas/workspaces.ts
+++ b/apps/web/lib/zod/schemas/workspaces.ts
@@ -67,6 +67,7 @@ export const WorkspaceSchema = z
tagsLimit: z.number().describe("The tags limit of the workspace."),
foldersUsage: z.number().describe("The folders usage of the workspace."),
foldersLimit: z.number().describe("The folders limit of the workspace."),
+ groupsLimit: z.number().describe("The groups limit of the workspace."),
usersLimit: z.number().describe("The users limit of the workspace."),
aiUsage: z.number().describe("The AI usage of the workspace."),
aiLimit: z.number().describe("The AI limit of the workspace."),
diff --git a/packages/prisma/schema/workspace.prisma b/packages/prisma/schema/workspace.prisma
index 78ae32bb7a..e61f088f3e 100644
--- a/packages/prisma/schema/workspace.prisma
+++ b/packages/prisma/schema/workspace.prisma
@@ -25,14 +25,14 @@ model Project {
payoutsUsage Int @default(0)
payoutsLimit Int @default(0)
payoutFee Float @default(0.05) // processing fee (in decimals) for partner payouts
-
- domainsLimit Int @default(3)
- tagsLimit Int @default(5)
- foldersUsage Int @default(0)
- foldersLimit Int @default(0)
- usersLimit Int @default(1)
- aiUsage Int @default(0)
- aiLimit Int @default(10)
+ domainsLimit Int @default(3)
+ tagsLimit Int @default(5)
+ foldersUsage Int @default(0)
+ foldersLimit Int @default(0)
+ groupsLimit Int @default(0)
+ usersLimit Int @default(1)
+ aiUsage Int @default(0)
+ aiLimit Int @default(10)
referralLinkId String? @unique
referredSignups Int @default(0)
diff --git a/packages/utils/src/constants/pricing.tsx b/packages/utils/src/constants/pricing.tsx
index bdacade187..363bb3a732 100644
--- a/packages/utils/src/constants/pricing.tsx
+++ b/packages/utils/src/constants/pricing.tsx
@@ -48,6 +48,7 @@ export const PLANS = [
domains: 3,
tags: 5,
folders: 0,
+ groups: 0,
users: 1,
ai: 10,
api: 60,
@@ -76,6 +77,7 @@ export const PLANS = [
domains: 10,
tags: 25,
folders: 3,
+ groups: 0,
users: 3,
ai: 1_000,
api: 600,
@@ -156,6 +158,7 @@ export const PLANS = [
domains: 100,
tags: INFINITY_NUMBER,
folders: 20,
+ groups: 3,
users: 10,
ai: 1_000,
api: 1_200,
@@ -253,6 +256,7 @@ export const PLANS = [
domains: 250,
tags: INFINITY_NUMBER,
folders: 50,
+ groups: 10,
users: 20,
ai: 1_000,
api: 3_000,
@@ -325,6 +329,7 @@ export const PLANS = [
domains: 250,
tags: INFINITY_NUMBER,
folders: INFINITY_NUMBER,
+ groups: INFINITY_NUMBER,
users: 30,
ai: 1_000,
api: 3_000,