Files
klz-cables.com/.pnpm-store/v10/files/cb/6d48885021d4d18636b383896c51e97737880437f5944733bf28689c022b7a64765656d5928c6c975f45fbaab29eeb6dae2132335ce9d5f93928c095102e08
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

64 lines
1.9 KiB
Plaintext

import { sql } from 'drizzle-orm';
import { buildVersionCollectionFields } from 'payload';
import { hasDraftsEnabled } from 'payload/shared';
import toSnakeCase from 'to-snake-case';
import { upsertRow } from './upsertRow/index.js';
import { getTransaction } from './utilities/getTransaction.js';
export async function createVersion({ autosave, collectionSlug, createdAt, parent, publishedLocale, req, returning, select, snapshot, updatedAt, versionData }) {
const collection = this.payload.collections[collectionSlug].config;
if (collection.versions.drafts) {
if (typeof select === 'object') {
select.updatedAt = true;
}
}
const defaultTableName = toSnakeCase(collection.slug);
const tableName = this.tableNameMap.get(`_${defaultTableName}${this.versionsSuffix}`);
const version = {
...versionData
};
if (version.id) {
delete version.id;
}
const data = {
autosave,
createdAt,
latest: true,
parent,
publishedLocale,
snapshot,
updatedAt,
version
};
const db = await getTransaction(this, req);
const result = await upsertRow({
adapter: this,
collectionSlug,
data,
db,
fields: buildVersionCollectionFields(this.payload.config, collection, true),
ignoreResult: returning === false ? 'idOnly' : undefined,
operation: 'create',
req,
select,
tableName
});
const table = this.tables[tableName];
if (hasDraftsEnabled(collection)) {
await this.execute({
db,
sql: sql`
UPDATE ${table}
SET latest = false
WHERE ${table.id} != ${result.id}
AND ${table.parent} = ${parent}
AND ${table.updatedAt} < ${result.updatedAt || updatedAt}
`
});
}
if (returning === false) {
return null;
}
return result;
}
//# sourceMappingURL=createVersion.js.map