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
45 lines
1.6 KiB
Plaintext
45 lines
1.6 KiB
Plaintext
import { combineWhereConstraints } from '../../utilities/combineWhereConstraints.js';
|
|
import { mergeListSearchAndWhere } from '../../utilities/mergeListSearchAndWhere.js';
|
|
export async function buildFolderWhereConstraints({ collectionConfig, folderID, localeCode, req, search = '', sort }) {
|
|
const constraints = [
|
|
mergeListSearchAndWhere({
|
|
collectionConfig,
|
|
search
|
|
})
|
|
];
|
|
const baseFilterConstraint = await (collectionConfig.admin?.baseFilter ?? collectionConfig.admin?.baseListFilter)?.({
|
|
limit: 0,
|
|
locale: localeCode,
|
|
page: 1,
|
|
req,
|
|
sort: sort || (typeof collectionConfig.defaultSort === 'string' ? collectionConfig.defaultSort : 'id')
|
|
});
|
|
if (baseFilterConstraint) {
|
|
constraints.push(baseFilterConstraint);
|
|
}
|
|
if (folderID) {
|
|
// build folder join where constraints
|
|
constraints.push({
|
|
relationTo: {
|
|
equals: collectionConfig.slug
|
|
}
|
|
});
|
|
// join queries need to omit trashed documents
|
|
if (collectionConfig.trash) {
|
|
constraints.push({
|
|
deletedAt: {
|
|
exists: false
|
|
}
|
|
});
|
|
}
|
|
}
|
|
const filteredConstraints = constraints.filter(Boolean);
|
|
if (filteredConstraints.length > 1) {
|
|
return combineWhereConstraints(filteredConstraints);
|
|
} else if (filteredConstraints.length === 1) {
|
|
return filteredConstraints[0];
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
//# sourceMappingURL=buildFolderWhereConstraints.js.map |