2
0

🐛 Fix new typebot creation host bubble parsing

This commit is contained in:
Baptiste Arnaud
2023-01-06 11:02:42 +01:00
parent 40d230a73a
commit 119f6dc348
2 changed files with 19 additions and 15 deletions

View File

@ -9,6 +9,7 @@ import {
} from 'utils/api'
import { getAuthenticatedUser } from '@/features/auth/api'
import { parseNewTypebot } from '@/features/dashboard'
import { NewTypebotProps } from '@/features/dashboard/api/parseNewTypebot'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
@ -86,14 +87,15 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
select: { plan: true },
})
if (!workspace) return notFound(res, "Couldn't find workspace")
const data =
const data = (
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
) as NewTypebotProps | Omit<NewTypebotProps, 'groups'>
const typebot = await prisma.typebot.create({
data:
'groups' in data
? data
: parseNewTypebot({
ownerAvatarUrl: user.image,
ownerAvatarUrl: user.image ?? undefined,
isBrandingEnabled: workspace.plan === Plan.FREE,
...data,
}),