diff --git a/apps/builder/src/features/results/api/procedures/getResultLogsProcedure.ts b/apps/builder/src/features/results/api/procedures/getResultLogsProcedure.ts index c269114dd..9af43c9be 100644 --- a/apps/builder/src/features/results/api/procedures/getResultLogsProcedure.ts +++ b/apps/builder/src/features/results/api/procedures/getResultLogsProcedure.ts @@ -1,5 +1,5 @@ +import { getTypebot } from '@/features/typebot/api/utils/getTypebot' import prisma from '@/lib/prisma' -import { canReadTypebots } from '@/utils/api/dbRules' import { authenticatedProcedure } from '@/utils/server/trpc' import { logSchema } from 'models' import { z } from 'zod' @@ -22,14 +22,15 @@ export const getResultLogsProcedure = authenticatedProcedure ) .output(z.object({ logs: z.array(logSchema) })) .query(async ({ input: { typebotId, resultId }, ctx: { user } }) => { - const typebot = await prisma.typebot.findFirst({ - where: canReadTypebots(typebotId, user), - select: { id: true }, + const typebot = await getTypebot({ + accessLevel: 'read', + user, + typebotId, }) if (!typebot) throw new Error('Typebot not found') const logs = await prisma.log.findMany({ where: { - result: { id: resultId, typebotId: typebot.id }, + resultId, }, }) diff --git a/apps/builder/src/features/results/api/procedures/getResultsProcedure.ts b/apps/builder/src/features/results/api/procedures/getResultsProcedure.ts index 30140339c..9329ced05 100644 --- a/apps/builder/src/features/results/api/procedures/getResultsProcedure.ts +++ b/apps/builder/src/features/results/api/procedures/getResultsProcedure.ts @@ -1,5 +1,5 @@ +import { getTypebot } from '@/features/typebot/api/utils/getTypebot' import prisma from '@/lib/prisma' -import { canReadTypebots } from '@/utils/api/dbRules' import { authenticatedProcedure } from '@/utils/server/trpc' import { TRPCError } from '@trpc/server' import { ResultWithAnswers, resultWithAnswersSchema } from 'models' @@ -38,11 +38,12 @@ export const getResultsProcedure = authenticatedProcedure message: 'limit must be between 1 and 200', }) const { cursor } = input - const typebot = await prisma.typebot.findFirst({ - where: canReadTypebots(input.typebotId, user), - select: { id: true }, + const typebot = await getTypebot({ + accessLevel: 'read', + user, + typebotId: input.typebotId, }) - if (!typebot) + if (!typebot?.id) throw new TRPCError({ code: 'NOT_FOUND', message: 'Typebot not found' }) const results = (await prisma.result.findMany({ take: limit + 1, diff --git a/apps/builder/src/features/typebot/api/utils/getTypebot.ts b/apps/builder/src/features/typebot/api/utils/getTypebot.ts index 355e0cedf..2f647f6c2 100644 --- a/apps/builder/src/features/typebot/api/utils/getTypebot.ts +++ b/apps/builder/src/features/typebot/api/utils/getTypebot.ts @@ -22,6 +22,7 @@ export const getTypebot = async ({ }, select: { ...select, + id: true, workspaceId: true, collaborators: { select: { userId: true, type: true } }, },