2
0

fix(results): 🐛 Remove storage on result delete

This commit is contained in:
Baptiste Arnaud
2022-06-26 18:17:50 +02:00
parent fc4db575ac
commit 56dca868c9
5 changed files with 2382 additions and 2782 deletions

View File

@@ -55,25 +55,24 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
id: ids.length > 0 ? { in: ids } : undefined,
typebot: canWriteTypebot(typebotId, user),
}
// Weird bug waiting for https://github.com/aws/aws-sdk-js/issues/4137
// const typebot = await prisma.typebot.findFirst({
// where: canWriteTypebot(typebotId, user),
// select: { groups: true },
// })
// if (!typebot) return forbidden(res)
// const fileUploadBlockIds = (typebot as Typebot).groups
// .flatMap((g) => g.blocks)
// .filter((b) => b.type === InputBlockType.FILE)
// .map((b) => b.id)
// if (fileUploadBlockIds.length > 0) {
// const filesToDelete = await prisma.answer.findMany({
// where: { result: resultsFilter, blockId: { in: fileUploadBlockIds } },
// })
// if (filesToDelete.length > 0)
// await deleteFiles({
// urls: filesToDelete.flatMap((a) => a.content.split(', ')),
// })
// }
const typebot = await prisma.typebot.findFirst({
where: canWriteTypebot(typebotId, user),
select: { groups: true },
})
if (!typebot) return forbidden(res)
const fileUploadBlockIds = (typebot as Typebot).groups
.flatMap((g) => g.blocks)
.filter((b) => b.type === InputBlockType.FILE)
.map((b) => b.id)
if (fileUploadBlockIds.length > 0) {
const filesToDelete = await prisma.answer.findMany({
where: { result: resultsFilter, blockId: { in: fileUploadBlockIds } },
})
if (filesToDelete.length > 0)
await deleteFiles({
urls: filesToDelete.flatMap((a) => a.content.split(', ')),
})
}
await prisma.log.deleteMany({
where: {
result: resultsFilter,