From 885dcecd8db922ff98c0676c44d9a25e7f7cd8d5 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Tue, 17 Oct 2023 14:19:09 +0200 Subject: [PATCH] :bug: (results) Lower the max limit in getResults endpoint to avoid payload size error Closes #908 --- apps/builder/src/features/results/api/getResults.ts | 6 +++--- .../results/components/table/ExportAllResultsModal.tsx | 2 +- .../builder/src/features/results/hooks/useResultsQuery.ts | 1 - apps/docs/openapi/builder/_spec_.json | 8 +++++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/builder/src/features/results/api/getResults.ts b/apps/builder/src/features/results/api/getResults.ts index 7abf26799..7b6371265 100644 --- a/apps/builder/src/features/results/api/getResults.ts +++ b/apps/builder/src/features/results/api/getResults.ts @@ -5,7 +5,7 @@ import { ResultWithAnswers, resultWithAnswersSchema } from '@typebot.io/schemas' import { z } from 'zod' import { isReadTypebotForbidden } from '@/features/typebot/helpers/isReadTypebotForbidden' -const maxLimit = 200 +const maxLimit = 100 export const getResults = authenticatedProcedure .meta({ @@ -20,7 +20,7 @@ export const getResults = authenticatedProcedure .input( z.object({ typebotId: z.string(), - limit: z.string().regex(/^[0-9]{1,3}$/), + limit: z.coerce.number().min(1).max(maxLimit).default(50), cursor: z.string().optional(), }) ) @@ -35,7 +35,7 @@ export const getResults = authenticatedProcedure if (limit < 1 || limit > maxLimit) throw new TRPCError({ code: 'BAD_REQUEST', - message: 'limit must be between 1 and 200', + message: `limit must be between 1 and ${maxLimit}`, }) const { cursor } = input const typebot = await prisma.typebot.findUnique({ diff --git a/apps/builder/src/features/results/components/table/ExportAllResultsModal.tsx b/apps/builder/src/features/results/components/table/ExportAllResultsModal.tsx index 443a71f4f..432619250 100644 --- a/apps/builder/src/features/results/components/table/ExportAllResultsModal.tsx +++ b/apps/builder/src/features/results/components/table/ExportAllResultsModal.tsx @@ -59,7 +59,7 @@ export const ExportAllResultsModal = ({ isOpen, onClose }: Props) => { const { results, nextCursor } = await trpcContext.results.getResults.fetch({ typebotId, - limit: '200', + limit: 100, cursor, }) allResults.push(...results) diff --git a/apps/builder/src/features/results/hooks/useResultsQuery.ts b/apps/builder/src/features/results/hooks/useResultsQuery.ts index f07951ab2..8c27bc8f4 100644 --- a/apps/builder/src/features/results/hooks/useResultsQuery.ts +++ b/apps/builder/src/features/results/hooks/useResultsQuery.ts @@ -11,7 +11,6 @@ export const useResultsQuery = ({ trpc.results.getResults.useInfiniteQuery( { typebotId, - limit: '50', }, { getNextPageParam: (lastPage) => lastPage.nextCursor, diff --git a/apps/docs/openapi/builder/_spec_.json b/apps/docs/openapi/builder/_spec_.json index 23175d546..253cd8c74 100644 --- a/apps/docs/openapi/builder/_spec_.json +++ b/apps/docs/openapi/builder/_spec_.json @@ -29833,10 +29833,12 @@ { "name": "limit", "in": "query", - "required": true, + "required": false, "schema": { - "type": "string", - "pattern": "^[0-9]{1,3}$" + "type": "number", + "minimum": 1, + "maximum": 100, + "default": 50 } }, {