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
67 lines
2.4 KiB
Plaintext
67 lines
2.4 KiB
Plaintext
import { executeAccess } from '../../auth/executeAccess.js';
|
|
import { combineQueries } from '../../database/combineQueries.js';
|
|
import { validateQueryPaths } from '../../database/queryValidation/validateQueryPaths.js';
|
|
import { buildVersionGlobalFields } from '../../index.js';
|
|
import { killTransaction } from '../../utilities/killTransaction.js';
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
export const countGlobalVersionsOperation = async (args)=>{
|
|
try {
|
|
const { disableErrors, global, overrideAccess, where } = args;
|
|
const req = args.req;
|
|
const { payload } = req;
|
|
// /////////////////////////////////////
|
|
// beforeOperation - Global
|
|
// /////////////////////////////////////
|
|
if (global.hooks?.beforeOperation?.length) {
|
|
for (const hook of global.hooks.beforeOperation){
|
|
args = await hook({
|
|
args,
|
|
context: req.context,
|
|
global,
|
|
operation: 'countVersions',
|
|
overrideAccess,
|
|
req
|
|
}) || args;
|
|
}
|
|
}
|
|
// /////////////////////////////////////
|
|
// Access
|
|
// /////////////////////////////////////
|
|
let accessResult;
|
|
if (!overrideAccess) {
|
|
accessResult = await executeAccess({
|
|
disableErrors,
|
|
req
|
|
}, global.access.readVersions);
|
|
// If errors are disabled, and access returns false, return empty results
|
|
if (accessResult === false) {
|
|
return {
|
|
totalDocs: 0
|
|
};
|
|
}
|
|
}
|
|
const fullWhere = combineQueries(where, accessResult);
|
|
const versionFields = buildVersionGlobalFields(payload.config, global, true);
|
|
await validateQueryPaths({
|
|
globalConfig: global,
|
|
overrideAccess: overrideAccess,
|
|
req,
|
|
versionFields,
|
|
where: where
|
|
});
|
|
const result = await payload.db.countGlobalVersions({
|
|
global: global.slug,
|
|
req,
|
|
where: fullWhere
|
|
});
|
|
// /////////////////////////////////////
|
|
// Return results
|
|
// /////////////////////////////////////
|
|
return result;
|
|
} catch (error) {
|
|
await killTransaction(args.req);
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
//# sourceMappingURL=countGlobalVersions.js.map |