chore: adjust rest endpoints to use new query property on req

This commit is contained in:
Jarrod Flesch
2024-03-07 15:42:46 -05:00
parent 21ee94739b
commit 20d0915a03
6 changed files with 11 additions and 26 deletions

View File

@@ -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
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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,