Skip to content

Commit 64443d8

Browse files
fix: thread req into interal folder payload operations (#12523)
1 parent feeee19 commit 64443d8

File tree

7 files changed

+28
-47
lines changed

7 files changed

+28
-47
lines changed

packages/next/src/views/BrowseByFolder/buildView.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ export const buildBrowseByFolderView = async (
7676

7777
const { breadcrumbs, documents, subfolders } = await getFolderData({
7878
folderID,
79-
payload: initPageResult.req.payload,
79+
req: initPageResult.req,
8080
search: query?.search as string,
81-
user: initPageResult.req.user,
8281
})
8382

8483
const resolvedFolderID = breadcrumbs[breadcrumbs.length - 1]?.id

packages/next/src/views/CollectionFolders/buildView.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ export const buildCollectionFolderView = async (
112112
const { breadcrumbs, documents, subfolders } = await getFolderData({
113113
collectionSlug,
114114
folderID,
115-
payload: initPageResult.req.payload,
115+
req: initPageResult.req,
116116
search: query?.search as string,
117-
user: initPageResult.req.user,
118117
})
119118

120119
const resolvedFolderID = breadcrumbs[breadcrumbs.length - 1]?.id

packages/payload/src/folders/endpoints/populateFolderData.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ export const populateFolderDataEndpoint: Endpoint = {
3333
const data = await getFolderData({
3434
collectionSlug: req.searchParams?.get('collectionSlug') || undefined,
3535
folderID: req.searchParams?.get('folderID') || undefined,
36-
payload: req.payload,
36+
req,
3737
search: req.searchParams?.get('search') || undefined,
38-
user: req.user,
3938
})
4039

4140
return Response.json(data)

packages/payload/src/folders/utils/getFolderBreadcrumbs.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import type { User } from '../../index.js'
2-
import type { Document, Payload } from '../../types/index.js'
1+
import type { Document, PayloadRequest } from '../../types/index.js'
32
import type { FolderBreadcrumb } from '../types.js'
43

54
type GetFolderBreadcrumbsArgs = {
65
breadcrumbs?: FolderBreadcrumb[]
76
folderID?: number | string
8-
payload: Payload
9-
user?: User
7+
req: PayloadRequest
108
}
119
/**
1210
* Builds breadcrumbs up from child folder
@@ -15,16 +13,17 @@ type GetFolderBreadcrumbsArgs = {
1513
export const getFolderBreadcrumbs = async ({
1614
breadcrumbs = [],
1715
folderID,
18-
payload,
19-
user,
16+
req,
2017
}: GetFolderBreadcrumbsArgs): Promise<FolderBreadcrumb[] | null> => {
18+
const { payload, user } = req
2119
const folderFieldName: string = payload.config.folders.fieldName
2220
if (folderID) {
2321
const folderQuery = await payload.find({
2422
collection: payload.config.folders.slug,
2523
depth: 0,
2624
limit: 1,
2725
overrideAccess: false,
26+
req,
2827
select: {
2928
name: true,
3029
[folderFieldName]: true,
@@ -52,8 +51,7 @@ export const getFolderBreadcrumbs = async ({
5251
typeof folder[folderFieldName] === 'string'
5352
? folder[folderFieldName]
5453
: folder[folderFieldName].id,
55-
payload,
56-
user,
54+
req,
5755
})
5856
}
5957
}

packages/payload/src/folders/utils/getFolderData.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { CollectionSlug, User } from '../../index.js'
2-
import type { Payload } from '../../types/index.js'
1+
import type { CollectionSlug } from '../../index.js'
2+
import type { PayloadRequest } from '../../types/index.js'
33
import type { GetFolderDataResult } from '../types.js'
44

55
import { parseDocumentID } from '../../index.js'
@@ -19,31 +19,22 @@ type Args = {
1919
* @default undefined
2020
*/
2121
folderID?: number | string
22-
/**
23-
* The locale to use for the document query
24-
* @default undefined
25-
*/
26-
payload: Payload
22+
req: PayloadRequest
2723
/**
2824
* Search term to filter documents by - only applicable IF `collectionSlug` exists and NO `folderID` is provided
2925
*/
3026
search?: string
31-
/**
32-
* The user making the request
33-
* @default undefined
34-
*/
35-
user?: User
3627
}
3728
/**
3829
* Query for documents, subfolders and breadcrumbs for a given folder
3930
*/
4031
export const getFolderData = async ({
4132
collectionSlug,
4233
folderID: _folderID,
43-
payload,
34+
req,
4435
search,
45-
user,
4636
}: Args): Promise<GetFolderDataResult> => {
37+
const { payload, user } = req
4738
const parentFolderID = parseDocumentID({
4839
id: _folderID,
4940
collectionSlug: payload.config.folders.slug,
@@ -52,17 +43,15 @@ export const getFolderData = async ({
5243

5344
const breadcrumbsPromise = getFolderBreadcrumbs({
5445
folderID: parentFolderID,
55-
payload,
56-
user,
46+
req,
5747
})
5848

5949
if (parentFolderID) {
6050
// subfolders and documents are queried together
6151
const documentAndSubfolderPromise = queryDocumentsAndFoldersFromJoin({
6252
collectionSlug,
6353
parentFolderID,
64-
payload,
65-
user,
54+
req,
6655
})
6756
const [breadcrumbs, documentsAndSubfolders] = await Promise.all([
6857
breadcrumbsPromise,
@@ -78,16 +67,14 @@ export const getFolderData = async ({
7867
// subfolders and documents are queried separately
7968
const subfoldersPromise = getOrphanedDocs({
8069
collectionSlug: payload.config.folders.slug,
81-
payload,
70+
req,
8271
search,
83-
user,
8472
})
8573
const documentsPromise = collectionSlug
8674
? getOrphanedDocs({
8775
collectionSlug,
88-
payload,
76+
req,
8977
search,
90-
user,
9178
})
9279
: Promise.resolve([])
9380
const [breadcrumbs, subfolders, documents] = await Promise.all([

packages/payload/src/folders/utils/getFoldersAndDocumentsFromJoin.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import type { User } from '../../auth/types.js'
21
import type { PaginatedDocs } from '../../database/types.js'
32
import type { CollectionSlug } from '../../index.js'
4-
import type { Document, Payload } from '../../types/index.js'
3+
import type { Document, PayloadRequest } from '../../types/index.js'
54
import type { FolderOrDocument } from '../types.js'
65

76
import { formatFolderOrDocumentItem } from './formatFolderOrDocumentItem.js'
@@ -13,15 +12,14 @@ type QueryDocumentsAndFoldersResults = {
1312
type QueryDocumentsAndFoldersArgs = {
1413
collectionSlug?: CollectionSlug
1514
parentFolderID: number | string
16-
payload: Payload
17-
user?: User
15+
req: PayloadRequest
1816
}
1917
export async function queryDocumentsAndFoldersFromJoin({
2018
collectionSlug,
2119
parentFolderID,
22-
payload,
23-
user,
20+
req,
2421
}: QueryDocumentsAndFoldersArgs): Promise<QueryDocumentsAndFoldersResults> {
22+
const { payload, user } = req
2523
const folderCollectionSlugs: string[] = payload.config.collections.reduce<string[]>(
2624
(acc, collection) => {
2725
if (collection?.folders) {
@@ -50,6 +48,7 @@ export async function queryDocumentsAndFoldersFromJoin({
5048
},
5149
limit: 1,
5250
overrideAccess: false,
51+
req,
5352
user,
5453
where: {
5554
id: {

packages/payload/src/folders/utils/getOrphanedDocs.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import type { CollectionSlug, Payload, User, Where } from '../../index.js'
1+
import type { CollectionSlug, PayloadRequest, Where } from '../../index.js'
22
import type { FolderOrDocument } from '../types.js'
33

44
import { formatFolderOrDocumentItem } from './formatFolderOrDocumentItem.js'
55

66
type Args = {
77
collectionSlug: CollectionSlug
8-
payload: Payload
8+
req: PayloadRequest
99
search?: string
10-
user?: User
1110
}
1211
export async function getOrphanedDocs({
1312
collectionSlug,
14-
payload,
13+
req,
1514
search,
16-
user,
1715
}: Args): Promise<FolderOrDocument[]> {
16+
const { payload, user } = req
1817
let whereConstraints: Where = {
1918
or: [
2019
{
@@ -42,6 +41,7 @@ export async function getOrphanedDocs({
4241
collection: collectionSlug,
4342
limit: 0,
4443
overrideAccess: false,
44+
req,
4545
sort: payload.collections[collectionSlug].config.admin.useAsTitle,
4646
user,
4747
where: whereConstraints,

0 commit comments

Comments
 (0)