✨ Add webhook blocks API public endpoints
This commit is contained in:
@ -0,0 +1 @@
|
||||
export * from './utils'
|
@ -0,0 +1,41 @@
|
||||
import prisma from '@/lib/prisma'
|
||||
import { canReadTypebots } from '@/utils/api/dbRules'
|
||||
import { User } from 'db'
|
||||
import {
|
||||
LogicBlockType,
|
||||
PublicTypebot,
|
||||
Typebot,
|
||||
TypebotLinkBlock,
|
||||
} from 'models'
|
||||
import { isDefined } from 'utils'
|
||||
|
||||
export const getLinkedTypebots = async (
|
||||
typebot: Pick<PublicTypebot, 'groups'>,
|
||||
user?: User
|
||||
): Promise<(Typebot | PublicTypebot)[]> => {
|
||||
const linkedTypebotIds = (
|
||||
typebot.groups
|
||||
.flatMap((g) => g.blocks)
|
||||
.filter(
|
||||
(s) =>
|
||||
s.type === LogicBlockType.TYPEBOT_LINK &&
|
||||
isDefined(s.options.typebotId)
|
||||
) as TypebotLinkBlock[]
|
||||
).map((s) => s.options.typebotId as string)
|
||||
if (linkedTypebotIds.length === 0) return []
|
||||
const typebots = (await ('typebotId' in typebot
|
||||
? prisma.publicTypebot.findMany({
|
||||
where: { id: { in: linkedTypebotIds } },
|
||||
})
|
||||
: prisma.typebot.findMany({
|
||||
where: user
|
||||
? {
|
||||
AND: [
|
||||
{ id: { in: linkedTypebotIds } },
|
||||
canReadTypebots(linkedTypebotIds, user as User),
|
||||
],
|
||||
}
|
||||
: { id: { in: linkedTypebotIds } },
|
||||
}))) as unknown as (Typebot | PublicTypebot)[]
|
||||
return typebots
|
||||
}
|
@ -0,0 +1 @@
|
||||
export * from './getLinkedTypebots'
|
@ -24,7 +24,6 @@ export const TypebotsDropdown = ({
|
||||
const { showToast } = useToast()
|
||||
const { typebots, isLoading } = useTypebots({
|
||||
workspaceId: currentWorkspaceId,
|
||||
allFolders: true,
|
||||
onError: (e) => showToast({ title: e.name, description: e.message }),
|
||||
})
|
||||
const currentTypebot = useMemo(
|
||||
|
Reference in New Issue
Block a user