Files
klz-cables.com/.pnpm-store/v10/files/2b/f8d8d142c148e35b30688943bbbed48fc79b544eac807bb01cea05e86e19eed6c8d977e9e68123d9f57189cab0bb71c5c2de6b33fd5f51e1c01d09d3164109
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

61 lines
2.0 KiB
Plaintext

export const enforceMaxVersions = async ({ id, collection, global: globalConfig, max, payload, req })=>{
const entityType = collection ? 'collection' : 'global';
const slug = collection ? collection.slug : globalConfig?.slug;
try {
const where = {};
let oldestAllowedDoc;
if (collection) {
where.parent = {
equals: id
};
const query = await payload.db.findVersions({
collection: collection.slug,
limit: 1,
page: max + 1,
pagination: false,
req,
sort: '-updatedAt',
where
});
[oldestAllowedDoc] = query.docs;
} else if (globalConfig) {
const query = await payload.db.findGlobalVersions({
global: globalConfig.slug,
limit: 1,
page: max + 1,
pagination: false,
req,
sort: '-updatedAt',
where
});
[oldestAllowedDoc] = query.docs;
}
if (oldestAllowedDoc?.updatedAt) {
const deleteQuery = {
updatedAt: {
less_than_equal: oldestAllowedDoc.updatedAt
}
};
if (collection) {
deleteQuery.parent = {
equals: id
};
}
const deleteVersionsArgs = {
req,
where: deleteQuery
};
if (globalConfig) {
deleteVersionsArgs.globalSlug = slug;
} else {
deleteVersionsArgs.collection = slug;
}
await payload.db.deleteVersions(deleteVersionsArgs);
}
} catch (err) {
payload.logger.error(err);
payload.logger.error(`There was an error cleaning up old versions for the ${entityType} ${slug}`);
}
};
//# sourceMappingURL=enforceMaxVersions.js.map