@@ -11,12 +11,12 @@ import { LogicBlockType } from '@typebot.io/schemas/features/blocks/logic/consta
|
||||
|
||||
type Props = {
|
||||
typebots: Pick<PublicTypebot, 'groups'>[]
|
||||
user?: User
|
||||
userId: string | undefined
|
||||
isPreview?: boolean
|
||||
}
|
||||
|
||||
export const getPreviouslyLinkedTypebots =
|
||||
({ typebots, user, isPreview }: Props) =>
|
||||
export const fetchLinkedChildTypebots =
|
||||
({ typebots, userId, isPreview }: Props) =>
|
||||
async (
|
||||
capturedLinkedBots: (Typebot | PublicTypebot)[]
|
||||
): Promise<(Typebot | PublicTypebot)[]> => {
|
||||
@@ -40,13 +40,13 @@ export const getPreviouslyLinkedTypebots =
|
||||
.filter(isDefined)
|
||||
if (linkedTypebotIds.length === 0) return capturedLinkedBots
|
||||
const linkedTypebots = (await fetchLinkedTypebots({
|
||||
user,
|
||||
userId,
|
||||
typebotIds: linkedTypebotIds,
|
||||
isPreview,
|
||||
})) as (Typebot | PublicTypebot)[]
|
||||
return getPreviouslyLinkedTypebots({
|
||||
return fetchLinkedChildTypebots({
|
||||
typebots: linkedTypebots,
|
||||
user,
|
||||
userId,
|
||||
isPreview,
|
||||
})([...capturedLinkedBots, ...linkedTypebots])
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { fetchLinkedTypebots } from './fetchLinkedTypebots'
|
||||
|
||||
type Props = {
|
||||
parentTypebotIds: string[]
|
||||
userId: string | undefined
|
||||
isPreview?: boolean
|
||||
}
|
||||
|
||||
export const fetchLinkedParentTypebots = ({
|
||||
parentTypebotIds,
|
||||
isPreview,
|
||||
userId,
|
||||
}: Props) =>
|
||||
parentTypebotIds.length > 0
|
||||
? fetchLinkedTypebots({
|
||||
typebotIds: parentTypebotIds,
|
||||
isPreview,
|
||||
userId,
|
||||
})
|
||||
: []
|
||||
@@ -1,20 +1,19 @@
|
||||
import prisma from '@typebot.io/lib/prisma'
|
||||
import { User } from '@typebot.io/prisma'
|
||||
|
||||
type Props = {
|
||||
isPreview?: boolean
|
||||
typebotIds: string[]
|
||||
user?: User
|
||||
userId: string | undefined
|
||||
}
|
||||
|
||||
export const fetchLinkedTypebots = async ({
|
||||
user,
|
||||
userId,
|
||||
isPreview,
|
||||
typebotIds,
|
||||
}: Props) => {
|
||||
if (!user || !isPreview)
|
||||
if (!userId || !isPreview)
|
||||
return prisma.publicTypebot.findMany({
|
||||
where: { id: { in: typebotIds } },
|
||||
where: { typebotId: { in: typebotIds } },
|
||||
})
|
||||
const linkedTypebots = await prisma.typebot.findMany({
|
||||
where: { id: { in: typebotIds } },
|
||||
@@ -39,7 +38,7 @@ export const fetchLinkedTypebots = async ({
|
||||
return linkedTypebots.filter(
|
||||
(typebot) =>
|
||||
typebot.collaborators.some(
|
||||
(collaborator) => collaborator.userId === user.id
|
||||
) || typebot.workspace.members.some((member) => member.userId === user.id)
|
||||
(collaborator) => collaborator.userId === userId
|
||||
) || typebot.workspace.members.some((member) => member.userId === userId)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user