Files
klz-cables.com/.pnpm-store/v10/files/96/a944a4143f5f576680d4d0dfa95a1654c963fdbf602067190833a656ce2ff210b81d098a5c51a8d19871ca646385c389dcec9bc8fd2ebf09438ab5f5d4a62e
Marc Mintel 5397309103
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
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

59 lines
1.6 KiB
Plaintext

import { combineQueries } from '../database/combineQueries.js';
import { hasDraftsEnabled } from '../utilities/getVersionsConfig.js';
import { appendVersionToQueryKey } from './drafts/appendVersionToQueryKey.js';
export const getLatestCollectionVersion = async ({ id, config, payload, published, query, req })=>{
let latestVersion;
const whereQuery = published ? {
and: [
{
parent: {
equals: id
}
},
{
'version._status': {
equals: 'published'
}
}
]
} : {
and: [
{
parent: {
equals: id
}
},
{
latest: {
equals: true
}
}
]
};
if (hasDraftsEnabled(config)) {
const { docs } = await payload.db.findVersions({
collection: config.slug,
limit: 1,
locale: req?.locale || query.locale,
pagination: false,
req,
sort: '-updatedAt',
where: combineQueries(appendVersionToQueryKey(query.where), whereQuery)
});
latestVersion = docs[0];
}
if (!latestVersion) {
if (!published) {
const doc = await payload.db.findOne({
...query,
req
});
return doc ?? undefined;
}
return undefined;
}
latestVersion.version.id = id;
return latestVersion.version;
};
//# sourceMappingURL=getLatestCollectionVersion.js.map