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
40 lines
1.3 KiB
Plaintext
40 lines
1.3 KiB
Plaintext
import { combineWhereConstraints } from '../../utilities/combineWhereConstraints.js';
|
|
import { formatFolderOrDocumentItem } from './formatFolderOrDocumentItem.js';
|
|
export async function getOrphanedDocs({ collectionSlug, folderFieldName, req, where }) {
|
|
const { payload, user } = req;
|
|
const noParentFolderConstraint = {
|
|
or: [
|
|
{
|
|
[folderFieldName]: {
|
|
exists: false
|
|
}
|
|
},
|
|
{
|
|
[folderFieldName]: {
|
|
equals: null
|
|
}
|
|
}
|
|
]
|
|
};
|
|
const orphanedFolders = await payload.find({
|
|
collection: collectionSlug,
|
|
limit: 0,
|
|
overrideAccess: false,
|
|
req,
|
|
sort: payload.collections[collectionSlug]?.config.admin.useAsTitle,
|
|
user,
|
|
where: where ? combineWhereConstraints([
|
|
noParentFolderConstraint,
|
|
where
|
|
]) : noParentFolderConstraint
|
|
});
|
|
return orphanedFolders?.docs.map((doc)=>formatFolderOrDocumentItem({
|
|
folderFieldName,
|
|
isUpload: Boolean(payload.collections[collectionSlug]?.config.upload),
|
|
relationTo: collectionSlug,
|
|
useAsTitle: payload.collections[collectionSlug]?.config.admin.useAsTitle,
|
|
value: doc
|
|
})) || [];
|
|
}
|
|
|
|
//# sourceMappingURL=getOrphanedDocs.js.map |