2
0

🗃️ Improve get typebot query performance

This commit is contained in:
Baptiste Arnaud
2023-02-13 09:37:59 +01:00
parent 770b29e767
commit c0757f8187

View File

@ -17,7 +17,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'GET') { if (req.method === 'GET') {
const typebot = await prisma.typebot.findFirst({ const typebot = await prisma.typebot.findFirst({
where: { where: {
...canReadTypebots(typebotId, user), id: typebotId,
isArchived: { not: true }, isArchived: { not: true },
}, },
include: { include: {
@ -27,6 +27,15 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
}, },
}) })
if (!typebot) return res.send({ typebot: null }) 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 } = const { publishedTypebot, collaborators, webhooks, ...restOfTypebot } =
typebot typebot
const isReadOnly = const isReadOnly =