2
0

♻️ Migrate from got to ky (#1416)

Closes #1415
This commit is contained in:
Baptiste Arnaud
2024-04-05 09:01:16 +02:00
committed by GitHub
parent ccc7101dd3
commit d96f384e02
59 changed files with 990 additions and 628 deletions

View File

@@ -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])
}

View File

@@ -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,
})
: []

View File

@@ -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)
)
}