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
29 lines
853 B
Plaintext
29 lines
853 B
Plaintext
/**
|
|
* This is a cross-entity way to count the number of versions for any given document.
|
|
* It will work for both collections and globals.
|
|
* @returns number of versions
|
|
*/ export const countVersions = async (args)=>{
|
|
const { collectionSlug, globalSlug, parentID, req } = args;
|
|
let countFn;
|
|
const where = {
|
|
parent: {
|
|
equals: parentID
|
|
}
|
|
};
|
|
if (collectionSlug) {
|
|
countFn = ()=>req.payload.countVersions({
|
|
collection: collectionSlug,
|
|
where
|
|
});
|
|
}
|
|
if (globalSlug) {
|
|
countFn = ()=>req.payload.countGlobalVersions({
|
|
global: globalSlug,
|
|
where
|
|
});
|
|
}
|
|
const res = countFn ? await countFn()?.then((res)=>res.totalDocs || 0) || 0 : 0;
|
|
return res;
|
|
};
|
|
|
|
//# sourceMappingURL=countVersions.js.map |