🐛 (usage) Archive typebot to be able to compute usage
This commit is contained in:
committed by
Baptiste Arnaud
parent
75ca255af2
commit
15dbc9577d
@ -31,6 +31,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
{
|
||||
workspace: { members: { some: { userId: user.id } } },
|
||||
id: { in: typebotIds },
|
||||
isArchived: { not: true },
|
||||
},
|
||||
{
|
||||
id: { in: typebotIds },
|
||||
@ -39,6 +40,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
userId: user.id,
|
||||
},
|
||||
},
|
||||
isArchived: { not: true },
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -51,6 +53,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
isArchived: { not: true },
|
||||
folderId,
|
||||
workspace: {
|
||||
id: workspaceId,
|
||||
@ -63,6 +66,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
},
|
||||
},
|
||||
{
|
||||
isArchived: { not: true },
|
||||
workspace: {
|
||||
id: workspaceId,
|
||||
members: {
|
||||
|
@ -13,13 +13,17 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const typebotId = req.query.typebotId as string
|
||||
if (req.method === 'GET') {
|
||||
const typebot = await prisma.typebot.findFirst({
|
||||
where: canReadTypebot(typebotId, user),
|
||||
where: {
|
||||
...canReadTypebot(typebotId, user),
|
||||
isArchived: { not: true },
|
||||
},
|
||||
include: {
|
||||
publishedTypebot: true,
|
||||
collaborators: { select: { userId: true, type: true } },
|
||||
webhooks: true,
|
||||
},
|
||||
})
|
||||
console.log(typebot)
|
||||
if (!typebot) return res.send({ typebot: null })
|
||||
const { publishedTypebot, collaborators, webhooks, ...restOfTypebot } =
|
||||
typebot
|
||||
@ -35,8 +39,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
}
|
||||
|
||||
if (req.method === 'DELETE') {
|
||||
const typebots = await prisma.typebot.deleteMany({
|
||||
const typebots = await prisma.typebot.updateMany({
|
||||
where: canWriteTypebot(typebotId, user),
|
||||
data: { isArchived: true },
|
||||
})
|
||||
await archiveResults(res)({
|
||||
typebotId,
|
||||
|
@ -2,7 +2,7 @@ import { withSentry } from '@sentry/nextjs'
|
||||
import { Prisma, Workspace, WorkspaceRole } from 'db'
|
||||
import prisma from 'libs/prisma'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { archiveResults, getAuthenticatedUser } from 'services/api/utils'
|
||||
import { getAuthenticatedUser } from 'services/api/utils'
|
||||
import { methodNotAllowed, notAuthenticated } from 'utils/api'
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
@ -28,23 +28,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
id,
|
||||
members: { some: { userId: user.id, role: WorkspaceRole.ADMIN } },
|
||||
}
|
||||
const deletedTypebots = await prisma.typebot.findMany({
|
||||
where: {
|
||||
workspace: workspaceFilter,
|
||||
},
|
||||
})
|
||||
await prisma.workspace.deleteMany({
|
||||
where: workspaceFilter,
|
||||
})
|
||||
await Promise.all(
|
||||
deletedTypebots.map((typebot) =>
|
||||
archiveResults(res)({
|
||||
typebotId: typebot.id,
|
||||
user,
|
||||
resultsFilter: { typebotId: typebot.id },
|
||||
})
|
||||
)
|
||||
)
|
||||
return res.status(200).json({
|
||||
message: 'success',
|
||||
})
|
||||
|
Reference in New Issue
Block a user