🐛 (limits) Fix storage limit trigger and e2e tests
This commit is contained in:
committed by
Baptiste Arnaud
parent
1e26703ad4
commit
30dff2d5d7
@ -76,6 +76,7 @@ const checkStorageLimit = async (typebotId: string) => {
|
||||
})
|
||||
if (!typebot?.workspace) throw new Error('Workspace not found')
|
||||
const { workspace } = typebot
|
||||
console.log(typebot.workspaceId)
|
||||
const {
|
||||
_sum: { storageUsed: totalStorageUsed },
|
||||
} = await prisma.answer.aggregate({
|
||||
@ -94,26 +95,27 @@ const checkStorageLimit = async (typebotId: string) => {
|
||||
if (!totalStorageUsed) return false
|
||||
const hasSentFirstEmail = workspace.storageLimitFirstEmailSentAt !== null
|
||||
const hasSentSecondEmail = workspace.storageLimitSecondEmailSentAt !== null
|
||||
const storageLimit = getStorageLimit(typebot.workspace) * 1024 * 1024 * 1024
|
||||
const storageLimit = getStorageLimit(typebot.workspace)
|
||||
const storageLimitBytes = storageLimit * 1024 * 1024 * 1024
|
||||
if (
|
||||
totalStorageUsed >= storageLimit * LIMIT_EMAIL_TRIGGER_PERCENT &&
|
||||
totalStorageUsed >= storageLimitBytes * LIMIT_EMAIL_TRIGGER_PERCENT &&
|
||||
!hasSentFirstEmail &&
|
||||
env('E2E_TEST') !== 'true'
|
||||
)
|
||||
sendAlmostReachStorageLimitEmail({
|
||||
await sendAlmostReachStorageLimitEmail({
|
||||
workspaceId: workspace.id,
|
||||
storageLimit,
|
||||
})
|
||||
if (
|
||||
totalStorageUsed >= storageLimit &&
|
||||
totalStorageUsed >= storageLimitBytes &&
|
||||
!hasSentSecondEmail &&
|
||||
env('E2E_TEST') !== 'true'
|
||||
)
|
||||
sendReachStorageLimitEmail({
|
||||
await sendReachStorageLimitEmail({
|
||||
workspaceId: workspace.id,
|
||||
storageLimit,
|
||||
})
|
||||
return (totalStorageUsed ?? 0) >= getStorageLimit(typebot?.workspace)
|
||||
return totalStorageUsed >= storageLimitBytes
|
||||
}
|
||||
|
||||
const sendAlmostReachStorageLimitEmail = async ({
|
||||
|
@ -69,8 +69,8 @@ const checkChatsUsage = async (
|
||||
| 'chatsLimitSecondEmailSentAt'
|
||||
>
|
||||
) => {
|
||||
const chatLimit = getChatsLimit(workspace)
|
||||
if (chatLimit === -1) return
|
||||
const chatsLimit = getChatsLimit(workspace)
|
||||
if (chatsLimit === -1) return
|
||||
const now = new Date()
|
||||
const firstDayOfMonth = new Date(now.getFullYear(), now.getMonth(), 1)
|
||||
const lastDayOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0)
|
||||
@ -91,26 +91,26 @@ const checkChatsUsage = async (
|
||||
workspace.chatsLimitSecondEmailSentAt < firstDayOfNextMonth &&
|
||||
workspace.chatsLimitSecondEmailSentAt > firstDayOfMonth
|
||||
if (
|
||||
chatsCount >= chatLimit * LIMIT_EMAIL_TRIGGER_PERCENT &&
|
||||
chatsCount >= chatsLimit * LIMIT_EMAIL_TRIGGER_PERCENT &&
|
||||
!hasSentFirstEmail &&
|
||||
env('E2E_TEST') !== 'true'
|
||||
)
|
||||
await sendAlmostReachChatsLimitEmail({
|
||||
workspaceId: workspace.id,
|
||||
chatLimit,
|
||||
chatLimit: chatsLimit,
|
||||
firstDayOfNextMonth,
|
||||
})
|
||||
if (
|
||||
chatsCount >= chatLimit &&
|
||||
chatsCount >= chatsLimit &&
|
||||
!hasSentSecondEmail &&
|
||||
env('E2E_TEST') !== 'true'
|
||||
)
|
||||
await sendReachedAlertEmail({
|
||||
workspaceId: workspace.id,
|
||||
chatLimit,
|
||||
chatLimit: chatsLimit,
|
||||
firstDayOfNextMonth,
|
||||
})
|
||||
return chatsCount >= chatLimit
|
||||
return chatsCount >= chatsLimit
|
||||
}
|
||||
|
||||
const sendAlmostReachChatsLimitEmail = async ({
|
||||
|
Reference in New Issue
Block a user