♻️ Remove storage limit related code
This commit is contained in:
@@ -27,7 +27,6 @@ export const createCheckoutSession = authenticatedProcedure
|
||||
plan: z.enum([Plan.STARTER, Plan.PRO]),
|
||||
returnUrl: z.string(),
|
||||
additionalChats: z.number(),
|
||||
additionalStorage: z.number(),
|
||||
vat: z
|
||||
.object({
|
||||
type: z.string(),
|
||||
@@ -53,7 +52,6 @@ export const createCheckoutSession = authenticatedProcedure
|
||||
plan,
|
||||
returnUrl,
|
||||
additionalChats,
|
||||
additionalStorage,
|
||||
isYearly,
|
||||
},
|
||||
ctx: { user },
|
||||
@@ -119,7 +117,6 @@ export const createCheckoutSession = authenticatedProcedure
|
||||
plan,
|
||||
returnUrl,
|
||||
additionalChats,
|
||||
additionalStorage,
|
||||
isYearly,
|
||||
})
|
||||
|
||||
@@ -142,7 +139,6 @@ type Props = {
|
||||
plan: 'STARTER' | 'PRO'
|
||||
returnUrl: string
|
||||
additionalChats: number
|
||||
additionalStorage: number
|
||||
isYearly: boolean
|
||||
userId: string
|
||||
}
|
||||
@@ -156,7 +152,6 @@ export const createCheckoutSessionUrl =
|
||||
plan,
|
||||
returnUrl,
|
||||
additionalChats,
|
||||
additionalStorage,
|
||||
isYearly,
|
||||
}: Props) => {
|
||||
const session = await stripe.checkout.sessions.create({
|
||||
@@ -173,17 +168,11 @@ export const createCheckoutSessionUrl =
|
||||
workspaceId,
|
||||
plan,
|
||||
additionalChats,
|
||||
additionalStorage,
|
||||
},
|
||||
currency,
|
||||
billing_address_collection: 'required',
|
||||
automatic_tax: { enabled: true },
|
||||
line_items: parseSubscriptionItems(
|
||||
plan,
|
||||
additionalChats,
|
||||
additionalStorage,
|
||||
isYearly
|
||||
),
|
||||
line_items: parseSubscriptionItems(plan, additionalChats, isYearly),
|
||||
})
|
||||
|
||||
return session.url
|
||||
|
||||
@@ -19,9 +19,7 @@ export const getUsage = authenticatedProcedure
|
||||
workspaceId: z.string(),
|
||||
})
|
||||
)
|
||||
.output(
|
||||
z.object({ totalChatsUsed: z.number(), totalStorageUsed: z.number() })
|
||||
)
|
||||
.output(z.object({ totalChatsUsed: z.number() }))
|
||||
.query(async ({ input: { workspaceId }, ctx: { user } }) => {
|
||||
const workspace = await prisma.workspace.findFirst({
|
||||
where: {
|
||||
@@ -55,20 +53,8 @@ export const getUsage = authenticatedProcedure
|
||||
},
|
||||
},
|
||||
})
|
||||
const {
|
||||
_sum: { storageUsed: totalStorageUsed },
|
||||
} = await prisma.answer.aggregate({
|
||||
where: {
|
||||
storageUsed: { gt: 0 },
|
||||
result: {
|
||||
typebotId: { in: workspace.typebots.map((typebot) => typebot.id) },
|
||||
},
|
||||
},
|
||||
_sum: { storageUsed: true },
|
||||
})
|
||||
|
||||
return {
|
||||
totalChatsUsed,
|
||||
totalStorageUsed: totalStorageUsed ?? 0,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -7,8 +7,8 @@ import { workspaceSchema } from '@typebot.io/schemas'
|
||||
import Stripe from 'stripe'
|
||||
import { isDefined } from '@typebot.io/lib'
|
||||
import { z } from 'zod'
|
||||
import { getChatsLimit, getStorageLimit } from '@typebot.io/lib/pricing'
|
||||
import { chatPriceIds, storagePriceIds } from './getSubscription'
|
||||
import { getChatsLimit } from '@typebot.io/lib/pricing'
|
||||
import { chatPriceIds } from './getSubscription'
|
||||
import { createCheckoutSessionUrl } from './createCheckoutSession'
|
||||
import { isAdminWriteWorkspaceForbidden } from '@/features/workspace/helpers/isAdminWriteWorkspaceForbidden'
|
||||
import { getUsage } from '@typebot.io/lib/api/getUsage'
|
||||
@@ -31,7 +31,6 @@ export const updateSubscription = authenticatedProcedure
|
||||
workspaceId: z.string(),
|
||||
plan: z.enum([Plan.STARTER, Plan.PRO]),
|
||||
additionalChats: z.number(),
|
||||
additionalStorage: z.number(),
|
||||
currency: z.enum(['usd', 'eur']),
|
||||
isYearly: z.boolean(),
|
||||
})
|
||||
@@ -48,7 +47,6 @@ export const updateSubscription = authenticatedProcedure
|
||||
workspaceId,
|
||||
plan,
|
||||
additionalChats,
|
||||
additionalStorage,
|
||||
currency,
|
||||
isYearly,
|
||||
returnUrl,
|
||||
@@ -100,9 +98,6 @@ export const updateSubscription = authenticatedProcedure
|
||||
const currentAdditionalChatsItemId = subscription?.items.data.find(
|
||||
(item) => chatPriceIds.includes(item.price.id)
|
||||
)?.id
|
||||
const currentAdditionalStorageItemId = subscription?.items.data.find(
|
||||
(item) => storagePriceIds.includes(item.price.id)
|
||||
)?.id
|
||||
const frequency = isYearly ? 'yearly' : 'monthly'
|
||||
|
||||
const items = [
|
||||
@@ -123,18 +118,6 @@ export const updateSubscription = authenticatedProcedure
|
||||
}),
|
||||
deleted: subscription ? additionalChats === 0 : undefined,
|
||||
},
|
||||
additionalStorage === 0 && !currentAdditionalStorageItemId
|
||||
? undefined
|
||||
: {
|
||||
id: currentAdditionalStorageItemId,
|
||||
price: priceIds[plan].storage[frequency],
|
||||
quantity: getStorageLimit({
|
||||
plan,
|
||||
additionalStorageIndex: additionalStorage,
|
||||
customStorageLimit: null,
|
||||
}),
|
||||
deleted: subscription ? additionalStorage === 0 : undefined,
|
||||
},
|
||||
].filter(isDefined)
|
||||
|
||||
if (subscription) {
|
||||
@@ -151,7 +134,6 @@ export const updateSubscription = authenticatedProcedure
|
||||
plan,
|
||||
returnUrl,
|
||||
additionalChats,
|
||||
additionalStorage,
|
||||
isYearly,
|
||||
})
|
||||
|
||||
@@ -175,7 +157,6 @@ export const updateSubscription = authenticatedProcedure
|
||||
data: {
|
||||
plan,
|
||||
additionalChatsIndex: additionalChats,
|
||||
additionalStorageIndex: additionalStorage,
|
||||
isQuarantined,
|
||||
},
|
||||
})
|
||||
@@ -188,7 +169,6 @@ export const updateSubscription = authenticatedProcedure
|
||||
data: {
|
||||
plan,
|
||||
additionalChatsIndex: additionalChats,
|
||||
additionalStorageIndex: additionalStorage,
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user