2
0

🐛 (results) Lower the max limit in getResults endpoint to avoid payload size error

Closes #908
This commit is contained in:
Baptiste Arnaud
2023-10-17 14:19:09 +02:00
parent 1cc4ccfcfa
commit 885dcecd8d
4 changed files with 9 additions and 8 deletions

View File

@ -5,7 +5,7 @@ import { ResultWithAnswers, resultWithAnswersSchema } from '@typebot.io/schemas'
import { z } from 'zod' import { z } from 'zod'
import { isReadTypebotForbidden } from '@/features/typebot/helpers/isReadTypebotForbidden' import { isReadTypebotForbidden } from '@/features/typebot/helpers/isReadTypebotForbidden'
const maxLimit = 200 const maxLimit = 100
export const getResults = authenticatedProcedure export const getResults = authenticatedProcedure
.meta({ .meta({
@ -20,7 +20,7 @@ export const getResults = authenticatedProcedure
.input( .input(
z.object({ z.object({
typebotId: z.string(), 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(), cursor: z.string().optional(),
}) })
) )
@ -35,7 +35,7 @@ export const getResults = authenticatedProcedure
if (limit < 1 || limit > maxLimit) if (limit < 1 || limit > maxLimit)
throw new TRPCError({ throw new TRPCError({
code: 'BAD_REQUEST', code: 'BAD_REQUEST',
message: 'limit must be between 1 and 200', message: `limit must be between 1 and ${maxLimit}`,
}) })
const { cursor } = input const { cursor } = input
const typebot = await prisma.typebot.findUnique({ const typebot = await prisma.typebot.findUnique({

View File

@ -59,7 +59,7 @@ export const ExportAllResultsModal = ({ isOpen, onClose }: Props) => {
const { results, nextCursor } = const { results, nextCursor } =
await trpcContext.results.getResults.fetch({ await trpcContext.results.getResults.fetch({
typebotId, typebotId,
limit: '200', limit: 100,
cursor, cursor,
}) })
allResults.push(...results) allResults.push(...results)

View File

@ -11,7 +11,6 @@ export const useResultsQuery = ({
trpc.results.getResults.useInfiniteQuery( trpc.results.getResults.useInfiniteQuery(
{ {
typebotId, typebotId,
limit: '50',
}, },
{ {
getNextPageParam: (lastPage) => lastPage.nextCursor, getNextPageParam: (lastPage) => lastPage.nextCursor,

View File

@ -29833,10 +29833,12 @@
{ {
"name": "limit", "name": "limit",
"in": "query", "in": "query",
"required": true, "required": false,
"schema": { "schema": {
"type": "string", "type": "number",
"pattern": "^[0-9]{1,3}$" "minimum": 1,
"maximum": 100,
"default": 50
} }
}, },
{ {