🗃️ Improve get typebot query performance
This commit is contained in:
@ -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 =
|
||||||
|
Reference in New Issue
Block a user