From c7d8d435f16b5bee8fb63fa183c38416b8f455ac Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Thu, 3 Aug 2023 15:17:57 -0400 Subject: [PATCH] fix: Only enforce min seats for orgs (#10572) * Only check subscription count for orgs * Undo constants change --------- Co-authored-by: alannnc --- packages/features/ee/teams/lib/payments.ts | 9 ++++++--- packages/lib/constants.ts | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/features/ee/teams/lib/payments.ts b/packages/features/ee/teams/lib/payments.ts index 048964b9ff..6171f159ae 100644 --- a/packages/features/ee/teams/lib/payments.ts +++ b/packages/features/ee/teams/lib/payments.ts @@ -3,6 +3,7 @@ import { z } from "zod"; import { getStripeCustomerIdFromUserId } from "@calcom/app-store/stripepayment/lib/customer"; import stripe from "@calcom/app-store/stripepayment/lib/server"; import { WEBAPP_URL } from "@calcom/lib/constants"; +import { ORGANIZATION_MIN_SEATS } from "@calcom/lib/constants"; import prisma from "@calcom/prisma"; import { teamMetadataSchema } from "@calcom/prisma/zod-utils"; @@ -74,7 +75,7 @@ export const purchaseTeamSubscription = async (input: { const getTeamWithPaymentMetadata = async (teamId: number) => { const team = await prisma.team.findUniqueOrThrow({ where: { id: teamId }, - select: { metadata: true, members: true }, + select: { metadata: true, members: true, _count: { select: { orgUsers: true } } }, }); const metadata = teamPaymentMetadataSchema.parse(team.metadata); return { ...team, metadata }; @@ -109,8 +110,10 @@ export const updateQuantitySubscriptionFromStripe = async (teamId: number) => { )?.quantity; if (!subscriptionQuantity) throw new Error("Subscription not found"); - if (membershipCount < subscriptionQuantity) { - console.info(`Team ${teamId} has less members than seats, skipping updating subscription.`); + if (!!team._count.orgUsers && membershipCount < ORGANIZATION_MIN_SEATS) { + console.info( + `Org ${teamId} has less members than the min ${ORGANIZATION_MIN_SEATS}, skipping updating subscription.` + ); return; } diff --git a/packages/lib/constants.ts b/packages/lib/constants.ts index d7f436b276..336b6d9761 100644 --- a/packages/lib/constants.ts +++ b/packages/lib/constants.ts @@ -90,3 +90,5 @@ export const MINUTES_TO_BOOK = process.env.NEXT_PUBLIC_MINUTES_TO_BOOK || "5"; // Needed for orgs export const ALLOWED_HOSTNAMES = JSON.parse(`[${process.env.ALLOWED_HOSTNAMES || ""}]`) as string[]; export const RESERVED_SUBDOMAINS = JSON.parse(`[${process.env.RESERVED_SUBDOMAINS || ""}]`) as string[]; + +export const ORGANIZATION_MIN_SEATS = 30;