✨ (editor) Add unpublish and close typebot options
Introducing more menu items on the "Publised" button in the editor. You can now unpublish a typebot and close it to new responses
This commit is contained in:
@ -2,7 +2,7 @@ import { withSentry } from '@sentry/nextjs'
|
||||
import prisma from 'libs/prisma'
|
||||
import { InputBlockType, PublicTypebot } from 'models'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { canPublishFileInput } from 'services/api/dbRules'
|
||||
import { canPublishFileInput, canWriteTypebot } from 'services/api/dbRules'
|
||||
import { getAuthenticatedUser } from 'services/api/utils'
|
||||
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils/api'
|
||||
|
||||
@ -32,6 +32,18 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
})
|
||||
return res.send({ typebots })
|
||||
}
|
||||
if (req.method === 'DELETE') {
|
||||
const publishedTypebotId = req.query.id as string
|
||||
const typebotId = req.query.typebotId as string | undefined
|
||||
if (!typebotId) return badRequest(res, 'typebotId is required')
|
||||
await prisma.publicTypebot.deleteMany({
|
||||
where: {
|
||||
id: publishedTypebotId,
|
||||
typebot: canWriteTypebot(typebotId, user),
|
||||
},
|
||||
})
|
||||
return res.send({ success: true })
|
||||
}
|
||||
return methodNotAllowed(res)
|
||||
}
|
||||
|
||||
|
@ -38,15 +38,18 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
}
|
||||
|
||||
if (req.method === 'DELETE') {
|
||||
const typebots = await prisma.typebot.updateMany({
|
||||
where: canWriteTypebot(typebotId, user),
|
||||
data: { isArchived: true },
|
||||
})
|
||||
await archiveResults(res)({
|
||||
typebotId,
|
||||
user,
|
||||
resultsFilter: { typebotId },
|
||||
})
|
||||
await prisma.publicTypebot.deleteMany({
|
||||
where: { typebot: canWriteTypebot(typebotId, user) },
|
||||
})
|
||||
const typebots = await prisma.typebot.updateMany({
|
||||
where: canWriteTypebot(typebotId, user),
|
||||
data: { isArchived: true },
|
||||
})
|
||||
return res.send({ typebots })
|
||||
}
|
||||
if (req.method === 'PUT') {
|
||||
|
Reference in New Issue
Block a user