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
28 lines
1009 B
Plaintext
28 lines
1009 B
Plaintext
import { buildVersionCollectionFields } from 'payload';
|
|
import toSnakeCase from 'to-snake-case';
|
|
import { buildQuery } from './queries/buildQuery.js';
|
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
export const countVersions = async function countVersions({ collection, locale, req, where: whereArg }) {
|
|
const collectionConfig = this.payload.collections[collection].config;
|
|
const tableName = this.tableNameMap.get(`_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`);
|
|
const fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true);
|
|
const { joins, where } = buildQuery({
|
|
adapter: this,
|
|
fields,
|
|
locale,
|
|
tableName,
|
|
where: whereArg
|
|
});
|
|
const db = await getTransaction(this, req);
|
|
const countResult = await this.countDistinct({
|
|
db,
|
|
joins,
|
|
tableName,
|
|
where
|
|
});
|
|
return {
|
|
totalDocs: countResult
|
|
};
|
|
};
|
|
|
|
//# sourceMappingURL=countVersions.js.map |