From 20d0915a03fc5526f257683c20ebf144b4c07e74 Mon Sep 17 00:00:00 2001 From: Jarrod Flesch Date: Thu, 7 Mar 2024 15:42:46 -0500 Subject: [PATCH] chore: adjust rest endpoints to use new query property on req --- packages/next/src/routes/rest/collections/delete.ts | 6 +----- packages/next/src/routes/rest/collections/find.ts | 5 +---- packages/next/src/routes/rest/collections/findVersions.ts | 6 +----- packages/next/src/routes/rest/collections/update.ts | 6 +----- packages/next/src/routes/rest/globals/findVersions.ts | 7 +------ packages/next/src/utilities/createPayloadRequest.ts | 7 ++++++- 6 files changed, 11 insertions(+), 26 deletions(-) diff --git a/packages/next/src/routes/rest/collections/delete.ts b/packages/next/src/routes/rest/collections/delete.ts index 790f94236..f574f88f5 100644 --- a/packages/next/src/routes/rest/collections/delete.ts +++ b/packages/next/src/routes/rest/collections/delete.ts @@ -4,15 +4,11 @@ import { getTranslation } from '@payloadcms/translations' import httpStatus from 'http-status' import { deleteOperation } from 'payload/operations' import { isNumber } from 'payload/utilities' -import qs from 'qs' import type { CollectionRouteHandler } from '../types.d.ts' export const deleteDoc: CollectionRouteHandler = async ({ collection, req }) => { - const { searchParams } = req - - // parse using `qs` to handle `where` queries - const { depth, where } = qs.parse(searchParams.toString()) as { + const { depth, where } = req.query as { depth?: string where?: Where } diff --git a/packages/next/src/routes/rest/collections/find.ts b/packages/next/src/routes/rest/collections/find.ts index 7d3e6a977..8ddae8bd1 100644 --- a/packages/next/src/routes/rest/collections/find.ts +++ b/packages/next/src/routes/rest/collections/find.ts @@ -3,14 +3,11 @@ import type { Where } from 'payload/types' import httpStatus from 'http-status' import { findOperation } from 'payload/operations' import { isNumber } from 'payload/utilities' -import qs from 'qs' import type { CollectionRouteHandler } from '../types.d.ts' export const find: CollectionRouteHandler = async ({ collection, req }) => { - const { searchParams } = req - // parse using `qs` to handle `where` queries - const { depth, draft, limit, page, sort, where } = qs.parse(searchParams.toString()) as { + const { depth, draft, limit, page, sort, where } = req.query as { depth?: string draft?: string limit?: string diff --git a/packages/next/src/routes/rest/collections/findVersions.ts b/packages/next/src/routes/rest/collections/findVersions.ts index 03857ae09..7a3c3f323 100644 --- a/packages/next/src/routes/rest/collections/findVersions.ts +++ b/packages/next/src/routes/rest/collections/findVersions.ts @@ -3,15 +3,11 @@ import type { Where } from 'payload/types' import httpStatus from 'http-status' import { findVersionsOperation } from 'payload/operations' import { isNumber } from 'payload/utilities' -import qs from 'qs' import type { CollectionRouteHandler } from '../types.d.ts' export const findVersions: CollectionRouteHandler = async ({ collection, req }) => { - const { searchParams } = req - - // parse using `qs` to handle `where` queries - const { depth, limit, page, sort, where } = qs.parse(searchParams.toString()) as { + const { depth, limit, page, sort, where } = req.query as { depth?: string limit?: string page?: string diff --git a/packages/next/src/routes/rest/collections/update.ts b/packages/next/src/routes/rest/collections/update.ts index df1adb1be..285f43b46 100644 --- a/packages/next/src/routes/rest/collections/update.ts +++ b/packages/next/src/routes/rest/collections/update.ts @@ -4,15 +4,11 @@ import { getTranslation } from '@payloadcms/translations' import httpStatus from 'http-status' import { updateOperation } from 'payload/operations' import { isNumber } from 'payload/utilities' -import qs from 'qs' import type { CollectionRouteHandler } from '../types.d.ts' export const update: CollectionRouteHandler = async ({ collection, req }) => { - const { searchParams } = req - - // parse using `qs` to handle `where` queries - const { depth, draft, where } = qs.parse(searchParams.toString()) as { + const { depth, draft, where } = req.query as { depth?: string draft?: string where?: Where diff --git a/packages/next/src/routes/rest/globals/findVersions.ts b/packages/next/src/routes/rest/globals/findVersions.ts index f96aa0059..43ba3d313 100644 --- a/packages/next/src/routes/rest/globals/findVersions.ts +++ b/packages/next/src/routes/rest/globals/findVersions.ts @@ -3,17 +3,12 @@ import type { Where } from 'payload/types' import httpStatus from 'http-status' import { findVersionsOperationGlobal } from 'payload/operations' import { isNumber } from 'payload/utilities' -import qs from 'qs' import type { GlobalRouteHandler } from '../types.d.ts' export const findVersions: GlobalRouteHandler = async ({ globalConfig, req }) => { - const { searchParams } = req - - // parse using `qs` to handle `where` queries - const { depth, draft, limit, page, sort, where } = qs.parse(searchParams.toString()) as { + const { depth, limit, page, sort, where } = req.query as { depth?: string - draft?: string limit?: string page?: string sort?: string diff --git a/packages/next/src/utilities/createPayloadRequest.ts b/packages/next/src/utilities/createPayloadRequest.ts index 08e9f67e1..c81d2e0b9 100644 --- a/packages/next/src/utilities/createPayloadRequest.ts +++ b/packages/next/src/utilities/createPayloadRequest.ts @@ -97,7 +97,12 @@ export const createPayloadRequest = async ({ port: urlProperties.port, protocol: urlProperties.protocol, query: urlProperties.search - ? QueryString.parse(urlProperties.search, { strictNullHandling: true }) + ? QueryString.parse(urlProperties.search, { + arrayLimit: 1000, + depth: 10, + ignoreQueryPrefix: true, + strictNullHandling: true, + }) : {}, routeParams: params || {}, search: urlProperties.search,