Files
klz-cables.com/.pnpm-store/v10/files/6f/3a7bd12ce271189bf15b2667e474e0cba55c94967a8749d6512e1b8d2ddb172b0358c11d511473a83f7ee7793c3feb090664824b87e37d502150e8ed0f19da
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

151 lines
2.8 KiB
Plaintext

import { logError } from 'payload';
export const fetchVersion = async ({
id,
collectionSlug,
depth,
globalSlug,
locale,
overrideAccess,
req,
select,
user
}) => {
try {
if (collectionSlug) {
return await req.payload.findVersionByID({
id: String(id),
collection: collectionSlug,
depth,
locale,
overrideAccess,
req,
select,
user
});
} else if (globalSlug) {
return await req.payload.findGlobalVersionByID({
id: String(id),
slug: globalSlug,
depth,
locale,
overrideAccess,
req,
select,
user
});
}
} catch (err) {
logError({
err,
payload: req.payload
});
return null;
}
};
export const fetchVersions = async ({
collectionSlug,
depth,
draft,
globalSlug,
limit,
locale,
overrideAccess,
page,
parentID,
req,
select,
sort,
user,
where: whereFromArgs
}) => {
const where = {
and: [...(whereFromArgs ? [whereFromArgs] : [])]
};
try {
if (collectionSlug) {
if (parentID) {
where.and.push({
parent: {
equals: parentID
}
});
}
return await req.payload.findVersions({
collection: collectionSlug,
depth,
draft,
limit,
locale,
overrideAccess,
page,
req,
select,
sort,
user,
where
});
} else if (globalSlug) {
return await req.payload.findGlobalVersions({
slug: globalSlug,
depth,
limit,
locale,
overrideAccess,
page,
req,
select,
sort,
user,
where
});
}
} catch (err) {
logError({
err,
payload: req.payload
});
return null;
}
};
export const fetchLatestVersion = async ({
collectionSlug,
depth,
globalSlug,
locale,
overrideAccess,
parentID,
req,
select,
status,
user,
where
}) => {
// Get the entity config to check if drafts are enabled
const entityConfig = collectionSlug ? req.payload.collections[collectionSlug]?.config : globalSlug ? req.payload.globals[globalSlug]?.config : undefined;
// Only query by _status if drafts are enabled (since _status field only exists with drafts)
const draftsEnabled = entityConfig?.versions?.drafts;
const and = [...(draftsEnabled ? [{
'version._status': {
equals: status
}
}] : []), ...(where ? [where] : [])];
const latest = await fetchVersions({
collectionSlug,
depth,
draft: true,
globalSlug,
limit: 1,
locale,
overrideAccess,
parentID,
req,
select,
sort: '-updatedAt',
user,
where: {
and
}
});
return latest?.docs?.length ? latest.docs[0] : null;
};
//# sourceMappingURL=fetchVersions.js.map