payload
Version:
Node, React, Headless CMS and Application Framework built on Next.js
52 lines (51 loc) • 1.94 kB
JavaScript
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;
// /////////////////////////////////////
// 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