diff --git a/apps/api/v2/src/modules/auth/guards/billing/platform-plan.guard.ts b/apps/api/v2/src/modules/auth/guards/billing/platform-plan.guard.ts index db162eabcf..2079c97313 100644 --- a/apps/api/v2/src/modules/auth/guards/billing/platform-plan.guard.ts +++ b/apps/api/v2/src/modules/auth/guards/billing/platform-plan.guard.ts @@ -1,6 +1,6 @@ import { PlatformPlan } from "@/modules/auth/decorators/billing/platform-plan.decorator"; import { ApiAuthGuardUser } from "@/modules/auth/strategies/api-auth/api-auth.strategy"; -import { PlatformPlanType } from "@/modules/billing/types"; +import { PlatformPlanType, orderedPlans } from "@/modules/billing/types"; import { OrganizationsRepository } from "@/modules/organizations/index/organizations.repository"; import { RedisService } from "@/modules/redis/redis.service"; import { Injectable, CanActivate, ExecutionContext, ForbiddenException } from "@nestjs/common"; @@ -61,7 +61,7 @@ export class PlatformPlanGuard implements CanActivate { !hasMinimumPlan({ currentPlan: organization.platformBilling?.plan as PlatformPlanType, minimumPlan: minimumPlan, - plans: ["FREE", "STARTER", "ESSENTIALS", "SCALE", "ENTERPRISE"], + plans: orderedPlans, }) ) { throw new ForbiddenException( @@ -79,7 +79,7 @@ export class PlatformPlanGuard implements CanActivate { type HasMinimumPlanProp = { currentPlan: PlatformPlanType; minimumPlan: PlatformPlanType; - plans: PlatformPlanType[]; + plans: readonly PlatformPlanType[]; }; export function hasMinimumPlan(props: HasMinimumPlanProp): boolean { @@ -87,7 +87,7 @@ export function hasMinimumPlan(props: HasMinimumPlanProp): boolean { const minimumPlanIndex = props.plans.indexOf(props.minimumPlan); if (currentPlanIndex === -1 || minimumPlanIndex === -1) { - throw new Error( + throw new ForbiddenException( `PlatformPlanGuard - Invalid platform billing plan provided. Current plan: ${props.currentPlan}, Minimum plan: ${props.minimumPlan}` ); } diff --git a/apps/api/v2/src/modules/billing/types.ts b/apps/api/v2/src/modules/billing/types.ts index 106d8d0afe..3576eb46c3 100644 --- a/apps/api/v2/src/modules/billing/types.ts +++ b/apps/api/v2/src/modules/billing/types.ts @@ -7,4 +7,13 @@ export enum PlatformPlan { PER_ACTIVE_USER = "PER_ACTIVE_USER", } -export type PlatformPlanType = "FREE" | "STARTER" | "ESSENTIALS" | "SCALE" | "ENTERPRISE" | "PER_ACTIVE_USER"; +export const orderedPlans = [ + "FREE", + "STARTER", + "ESSENTIALS", + "SCALE", + "PER_ACTIVE_USER", + "ENTERPRISE", +] as const; + +export type PlatformPlanType = (typeof orderedPlans)[number];