Files
klz-cables.com/.pnpm-store/v10/files/72/a2573d539ff4f0f7b0b5911bc5c6bc4416e7d2ef83739ba3e411a0f01fa03b07987a8700e06ebdb6db8ac34a7fd9d2cfdaceb48146b5076922cb5aa2de6edf
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

47 lines
1.7 KiB
Plaintext

import { inArray } from 'drizzle-orm';
import { APIError, buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
import toSnakeCase from 'to-snake-case';
import { findMany } from './find/findMany.js';
import { getTransaction } from './utilities/getTransaction.js';
export const deleteVersions = async function deleteVersion({ collection: collectionSlug, globalSlug, locale, req, where: where }) {
let tableName;
let fields;
if (globalSlug) {
const globalConfig = this.payload.globals.config.find(({ slug })=>slug === globalSlug);
tableName = this.tableNameMap.get(`_${toSnakeCase(globalSlug)}${this.versionsSuffix}`);
fields = buildVersionGlobalFields(this.payload.config, globalConfig, true);
} else if (collectionSlug) {
const collectionConfig = this.payload.collections[collectionSlug].config;
tableName = this.tableNameMap.get(`_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`);
fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true);
} else {
throw new APIError('Either collection or globalSlug must be passed.');
}
const { docs } = await findMany({
adapter: this,
fields,
joins: false,
limit: 0,
locale,
page: 1,
pagination: false,
req,
tableName,
where
});
const ids = [];
docs.forEach((doc)=>{
ids.push(doc.id);
});
if (ids.length > 0) {
const db = await getTransaction(this, req);
await this.deleteWhere({
db,
tableName,
where: inArray(this.tables[tableName].id, ids)
});
}
return docs;
};
//# sourceMappingURL=deleteVersions.js.map