Files
speckle-server/packages/server/modules/cli/commands/workspaces/set-plan.ts
T
Kristaps Fabians Geikins 211922b6a6 chore: get rid of all old workspace plan code (#4624)
* first batch of changes

* tests fix

* FE fixed

* renaming constants

* test fixes

* moar test fixes

* another test fix

* reenable app rover check

---------

Co-authored-by: Gergő Jedlicska <gergo@jedlicska.com>
2025-04-30 19:18:32 +02:00

69 lines
2.1 KiB
TypeScript

import { CommandModule } from 'yargs'
import { cliLogger as logger } from '@/observability/logging'
import {
getWorkspaceBySlugOrIdFactory,
getWorkspaceFactory
} from '@/modules/workspaces/repositories/workspaces'
import { db } from '@/db/knex'
import { upsertWorkspacePlanFactory } from '@/modules/gatekeeper/repositories/billing'
import { WorkspaceNotFoundError } from '@/modules/workspaces/errors/workspace'
import { PaidWorkspacePlans, PaidWorkspacePlanStatuses } from '@speckle/shared'
import { getEventBus } from '@/modules/shared/services/eventBus'
import { updateWorkspacePlanFactory } from '@/modules/gatekeeper/services/workspacePlans'
const command: CommandModule<
unknown,
{
workspaceSlugOrId: string
status: PaidWorkspacePlanStatuses
plan: PaidWorkspacePlans
}
> = {
command: 'set-plan <workspaceSlugOrId> [plan] [status]',
describe: 'Set a plan for a workspace.',
builder: {
workspaceSlugOrId: {
describe: 'Workspace ID or slug',
type: 'string'
},
plan: {
describe: 'Plan to set the status for',
type: 'string',
default: PaidWorkspacePlans.Team,
choices: [PaidWorkspacePlans.Team, PaidWorkspacePlans.Pro]
},
status: {
describe: 'Status to set for the workspace plan',
type: 'string',
default: 'valid',
choices: ['valid', 'paymentFailed', 'cancelationScheduled', 'canceled']
}
},
handler: async (args) => {
logger.info(
`Setting plan for workspace '${args.workspaceSlugOrId}' to '${args.plan}' with status '${args.status}'`
)
const workspace = await getWorkspaceBySlugOrIdFactory({ db })(args)
if (!workspace) {
throw new WorkspaceNotFoundError(
`Workspace w/ slug or id '${args.workspaceSlugOrId}' not found`
)
}
const updateWorkspacePlan = updateWorkspacePlanFactory({
getWorkspace: getWorkspaceFactory({ db }),
upsertWorkspacePlan: upsertWorkspacePlanFactory({ db }),
emitEvent: getEventBus().emit
})
await updateWorkspacePlan({
workspaceId: workspace.id,
name: args.plan,
status: args.status
})
logger.info(`Plan set!`)
}
}
export = command