Files
klz-cables.com/.pnpm-store/v10/files/5e/ae6258b373a78b6f05c0fef9b42844e4499fe373d2f2af633c792c6054645e928993347e2a3600e980902e0f1445f030cf19ab7bc0474209de7175965d3ffd
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

66 lines
2.2 KiB
Plaintext

import { APIError } from '../../errors/APIError.js';
import { combineWhereConstraints } from '../../utilities/combineWhereConstraints.js';
import { formatFolderOrDocumentItem } from './formatFolderOrDocumentItem.js';
export async function queryDocumentsAndFoldersFromJoin({ documentWhere, folderWhere, parentFolderID, req }) {
const { payload, user } = req;
if (payload.config.folders === false) {
throw new APIError('Folders are not enabled', 500);
}
const subfolderDoc = await payload.find({
collection: payload.config.folders.slug,
depth: 1,
joins: {
documentsAndFolders: {
limit: 100_000_000,
sort: 'name',
where: combineWhereConstraints([
folderWhere,
documentWhere
], 'or')
}
},
limit: 1,
overrideAccess: false,
req,
select: {
documentsAndFolders: true,
folderType: true
},
user,
where: {
id: {
equals: parentFolderID
}
}
});
const childrenDocs = subfolderDoc?.docs[0]?.documentsAndFolders?.docs || [];
const results = childrenDocs.reduce((acc, doc)=>{
if (!payload.config.folders) {
return acc;
}
const { relationTo, value } = doc;
const item = formatFolderOrDocumentItem({
folderFieldName: payload.config.folders.fieldName,
isUpload: Boolean(payload.collections[relationTo].config.upload),
relationTo,
useAsTitle: payload.collections[relationTo].config.admin?.useAsTitle,
value
});
if (relationTo === payload.config.folders.slug) {
acc.subfolders.push(item);
} else {
acc.documents.push(item);
}
return acc;
}, {
documents: [],
subfolders: []
});
return {
documents: results.documents,
folderAssignedCollections: subfolderDoc?.docs[0]?.folderType || [],
subfolders: results.subfolders
};
}
//# sourceMappingURL=getFoldersAndDocumentsFromJoin.js.map