Skip to content

Commit

Permalink
🐛 (typebot) Make sure old typebot properties are removed when pulled
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Feb 19, 2023
1 parent c32aadc commit d22cc45
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { omit } from 'utils'

export const removeTypebotOldProperties = (data: unknown) => {
if (!data || typeof data !== 'object') return data
if ('publishedTypebotId' in data) {
return omit(data, 'publishedTypebotId')
}
return data
}
11 changes: 6 additions & 5 deletions apps/builder/src/pages/api/typebots/[typebotId].ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { Typebot } from 'models'
import { omit } from 'utils'
import { getTypebot } from '@/features/typebot/api/utils/getTypebot'
import { isReadTypebotForbidden } from '@/features/typebot/api/utils/isReadTypebotForbidden'
import { removeTypebotOldProperties } from '@/features/typebot/api/utils/removeTypebotOldProperties'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
if (!user) return notAuthenticated(res)

const typebotId = req.query.typebotId as string
if (req.method === 'GET') {
const typebot = await prisma.typebot.findFirst({
const fullTypebot = await prisma.typebot.findFirst({
where: {
id: typebotId,
isArchived: { not: true },
Expand All @@ -26,16 +27,16 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
webhooks: true,
},
})
if (!typebot || (await isReadTypebotForbidden(typebot, user)))
if (!fullTypebot || (await isReadTypebotForbidden(fullTypebot, user)))
return res.status(404).send({ typebot: null })

const { publishedTypebot, collaborators, webhooks, ...restOfTypebot } =
typebot
const { publishedTypebot, collaborators, webhooks, ...typebot } =
fullTypebot
const isReadOnly =
collaborators.find((c) => c.userId === user.id)?.type ===
CollaborationType.READ
return res.send({
typebot: restOfTypebot,
typebot: removeTypebotOldProperties(typebot),
publishedTypebot,
isReadOnly,
webhooks,
Expand Down

0 comments on commit d22cc45

Please sign in to comment.