fix: Only enforce min seats for orgs (#10572)

* Only check subscription count for orgs

* Undo constants change

---------

Co-authored-by: alannnc <alannnc@gmail.com>
pull/10580/head
Joe Au-Yeung 2023-08-03 15:17:57 -04:00 committed by GitHub
parent 506ef2078f
commit c7d8d435f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -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;
}

View File

@ -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;