2
0

(billing) Implement custom plan

This commit is contained in:
Baptiste Arnaud
2022-10-27 11:32:21 +02:00
committed by Baptiste Arnaud
parent 3f7dc79918
commit 385853ca3c
23 changed files with 395 additions and 68 deletions

View File

@ -1,4 +1,4 @@
import { Plan, PrismaClient, User, Workspace, WorkspaceRole } from 'db'
import { Plan, Prisma, PrismaClient, User, Workspace, WorkspaceRole } from 'db'
import cuid from 'cuid'
import { Typebot, Webhook } from 'models'
import { readFileSync } from 'fs'
@ -166,3 +166,13 @@ export const updateTypebot = async (
data: partialTypebot,
})
}
export const updateWorkspace = async (
id: string,
data: Prisma.WorkspaceUncheckedUpdateManyInput
) => {
await prisma.workspace.updateMany({
where: { id: proWorkspaceId },
data,
})
}

View File

@ -13,17 +13,16 @@ export const proWorkspaceId = 'proWorkspace'
export const freeWorkspaceId = 'freeWorkspace'
export const starterWorkspaceId = 'starterWorkspace'
export const lifetimeWorkspaceId = 'lifetimeWorkspaceId'
export const customWorkspaceId = 'customWorkspaceId'
const setupWorkspaces = async () => {
await prisma.workspace.create({
data: {
id: freeWorkspaceId,
name: 'Free workspace',
plan: Plan.FREE,
},
})
await prisma.workspace.createMany({
data: [
{
id: freeWorkspaceId,
name: 'Free workspace',
plan: Plan.FREE,
},
{
id: starterWorkspaceId,
name: 'Starter workspace',
@ -40,6 +39,14 @@ const setupWorkspaces = async () => {
name: 'Lifetime workspace',
plan: Plan.LIFETIME,
},
{
id: customWorkspaceId,
name: 'Custom workspace',
plan: Plan.CUSTOM,
customChatsLimit: 100000,
customStorageLimit: 50,
customSeatsLimit: 20,
},
],
})
}
@ -99,6 +106,11 @@ export const setupUsers = async () => {
userId,
workspaceId: lifetimeWorkspaceId,
},
{
role: WorkspaceRole.ADMIN,
userId,
workspaceId: customWorkspaceId,
},
],
})
}