2
0

🧑‍💻 (s3) Correctly delete the files when deleting resources

This commit is contained in:
Baptiste Arnaud
2024-09-02 11:23:01 +02:00
parent f53705268c
commit 041b817aa0
16 changed files with 225 additions and 206 deletions

View File

@@ -43,6 +43,7 @@ export const deleteResults = authenticatedProcedure
groups: true,
workspace: {
select: {
id: true,
isSuspended: true,
isPastDue: true,
members: {
@@ -65,8 +66,10 @@ export const deleteResults = authenticatedProcedure
throw new TRPCError({ code: 'NOT_FOUND', message: 'Typebot not found' })
const { success } = await archiveResults(prisma)({
typebot: {
groups: typebot.groups,
} as Pick<Typebot, 'groups'>,
id: typebotId,
workspaceId: typebot.workspace.id,
groups: typebot.groups as Typebot['groups'],
},
resultsFilter: {
id: (idsArray?.length ?? 0) > 0 ? { in: idsArray } : undefined,
typebotId,

View File

@@ -5,6 +5,7 @@ import { Typebot } from '@typebot.io/schemas'
import { z } from 'zod'
import { isWriteTypebotForbidden } from '../helpers/isWriteTypebotForbidden'
import { archiveResults } from '@typebot.io/results/archiveResults'
import { removeObjectsFromTypebot } from '@typebot.io/lib/s3/removeObjectsRecursively'
export const deleteTypebot = authenticatedProcedure
.meta({
@@ -40,6 +41,7 @@ export const deleteTypebot = authenticatedProcedure
groups: true,
workspace: {
select: {
id: true,
isSuspended: true,
isPastDue: true,
members: {
@@ -66,8 +68,10 @@ export const deleteTypebot = authenticatedProcedure
const { success } = await archiveResults(prisma)({
typebot: {
groups: existingTypebot.groups,
} as Pick<Typebot, 'groups'>,
id: typebotId,
workspaceId: existingTypebot.workspace.id,
groups: existingTypebot.groups as Typebot['groups'],
},
resultsFilter: { typebotId },
})
if (!success)
@@ -82,6 +86,10 @@ export const deleteTypebot = authenticatedProcedure
where: { id: typebotId },
data: { isArchived: true, publicId: null, customDomain: null },
})
await removeObjectsFromTypebot({
workspaceId: existingTypebot.workspace.id,
typebotId,
})
return {
message: 'success',
}

View File

@@ -6,6 +6,7 @@ import { TRPCError } from '@trpc/server'
import { isNotEmpty } from '@typebot.io/lib/utils'
import Stripe from 'stripe'
import { env } from '@typebot.io/env'
import { removeObjectsFromWorkspace } from '@typebot.io/lib/s3/removeObjectsRecursively'
export const deleteWorkspace = authenticatedProcedure
.meta({
@@ -44,6 +45,8 @@ export const deleteWorkspace = authenticatedProcedure
where: { id: workspaceId },
})
await removeObjectsFromWorkspace(workspaceId)
if (isNotEmpty(workspace.stripeId) && env.STRIPE_SECRET_KEY) {
const stripe = new Stripe(env.STRIPE_SECRET_KEY, {
apiVersion: '2022-11-15',