From fb7a7684e7f57fa755799bf73ffafc2c22a671e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Jedlicska?= Date: Wed, 11 Dec 2024 16:07:49 +0100 Subject: [PATCH] refactor(gatekeeper): use exhaustive switch pattern --- .../modules/gatekeeper/domain/constants.ts | 7 ----- .../modules/gatekeeper/services/readOnly.ts | 30 ++++++++----------- 2 files changed, 13 insertions(+), 24 deletions(-) delete mode 100644 packages/server/modules/gatekeeper/domain/constants.ts diff --git a/packages/server/modules/gatekeeper/domain/constants.ts b/packages/server/modules/gatekeeper/domain/constants.ts deleted file mode 100644 index cfc6f3607..000000000 --- a/packages/server/modules/gatekeeper/domain/constants.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { z } from 'zod' - -export const workspacePlanStatusValid = z.literal('valid') -export const workspacePlanStatusPaymentFailed = z.literal('paymentFailed') -export const workspacePlanStatusCancelationScheduled = z.literal('cancelationScheduled') -export const workspacePlanStatusCanceled = z.literal('canceled') -export const workspacePlanStatusExpired = z.literal('expired') diff --git a/packages/server/modules/gatekeeper/services/readOnly.ts b/packages/server/modules/gatekeeper/services/readOnly.ts index 1e2fefcab..9c4936574 100644 --- a/packages/server/modules/gatekeeper/services/readOnly.ts +++ b/packages/server/modules/gatekeeper/services/readOnly.ts @@ -1,17 +1,6 @@ import { GetWorkspacePlan } from '@/modules/gatekeeper/domain/billing' import { Workspace } from '@/modules/workspacesCore/domain/types' -import { z } from 'zod' -import { - workspacePlanStatusCanceled, - workspacePlanStatusExpired, - workspacePlanStatusPaymentFailed -} from '@/modules/gatekeeper/domain/constants' - -const readOnlyWorkspacePlanStatuses = z.union([ - workspacePlanStatusPaymentFailed, - workspacePlanStatusCanceled, - workspacePlanStatusExpired -]) +import { throwUncoveredError } from '@speckle/shared' export const isWorkspaceReadOnlyFactory = ({ getWorkspacePlan }: { getWorkspacePlan: GetWorkspacePlan }) => @@ -20,9 +9,16 @@ export const isWorkspaceReadOnlyFactory = // Should never happen if (!workspacePlan) return true - const { success: workspaceReadOnly } = readOnlyWorkspacePlanStatuses.safeParse( - workspacePlan.status - ) - - return workspaceReadOnly + switch (workspacePlan.status) { + case 'cancelationScheduled': + case 'valid': + case 'trial': + case 'paymentFailed': + return false + case 'expired': + case 'canceled': + return true + default: + throwUncoveredError(workspacePlan) + } }