From c0757f81872dfcf97d071f7f82f6c2f01accc098 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Mon, 13 Feb 2023 09:37:59 +0100 Subject: [PATCH] :card_file_box: Improve get typebot query performance --- apps/builder/src/pages/api/typebots/[typebotId].ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/builder/src/pages/api/typebots/[typebotId].ts b/apps/builder/src/pages/api/typebots/[typebotId].ts index 8a03a944b..5fa2220ae 100644 --- a/apps/builder/src/pages/api/typebots/[typebotId].ts +++ b/apps/builder/src/pages/api/typebots/[typebotId].ts @@ -17,7 +17,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { if (req.method === 'GET') { const typebot = await prisma.typebot.findFirst({ where: { - ...canReadTypebots(typebotId, user), + id: typebotId, isArchived: { not: true }, }, include: { @@ -27,6 +27,15 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { }, }) if (!typebot) return res.send({ typebot: null }) + const memberInWorkspace = await prisma.memberInWorkspace.findFirst({ + where: { + workspaceId: typebot.workspaceId, + userId: user.id, + }, + }) + if (process.env.ADMIN_EMAIL !== user.email && !memberInWorkspace) + return res.send({ typebot: null }) + const { publishedTypebot, collaborators, webhooks, ...restOfTypebot } = typebot const isReadOnly =