🐛 Fix new typebot creation host bubble parsing
This commit is contained in:
@ -7,6 +7,20 @@ import {
|
||||
Typebot,
|
||||
} from 'models'
|
||||
|
||||
export type NewTypebotProps = Omit<
|
||||
Typebot,
|
||||
| 'createdAt'
|
||||
| 'updatedAt'
|
||||
| 'id'
|
||||
| 'publishedTypebotId'
|
||||
| 'publicId'
|
||||
| 'customDomain'
|
||||
| 'icon'
|
||||
| 'isArchived'
|
||||
| 'isClosed'
|
||||
| 'resultsTablePreferences'
|
||||
>
|
||||
|
||||
export const parseNewTypebot = ({
|
||||
folderId,
|
||||
name,
|
||||
@ -19,19 +33,7 @@ export const parseNewTypebot = ({
|
||||
name: string
|
||||
ownerAvatarUrl?: string
|
||||
isBrandingEnabled?: boolean
|
||||
}): Omit<
|
||||
Typebot,
|
||||
| 'createdAt'
|
||||
| 'updatedAt'
|
||||
| 'id'
|
||||
| 'publishedTypebotId'
|
||||
| 'publicId'
|
||||
| 'customDomain'
|
||||
| 'icon'
|
||||
| 'isArchived'
|
||||
| 'isClosed'
|
||||
| 'resultsTablePreferences'
|
||||
> => {
|
||||
}): NewTypebotProps => {
|
||||
const startGroupId = cuid()
|
||||
const startBlockId = cuid()
|
||||
const startBlock: StartBlock = {
|
||||
|
@ -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,
|
||||
}),
|
||||
|
Reference in New Issue
Block a user