Files
klz-cables.com/.pnpm-store/v10/files/48/d1c61af794f9438a1ff56d72bcbdd04cb31785f7c976892b5035c4ad74aafc8664e92fd2bc37b4d8ee2277631cbbad4851dd9ff5b2a54a145c8fd20a51a723
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
2.1 KiB
Plaintext

import { eq } from 'drizzle-orm';
import toSnakeCase from 'to-snake-case';
import { buildFindManyArgs } from './find/buildFindManyArgs.js';
import { buildQuery } from './queries/buildQuery.js';
import { selectDistinct } from './queries/selectDistinct.js';
import { transform } from './transform/read/index.js';
import { getTransaction } from './utilities/getTransaction.js';
export const deleteOne = async function deleteOne({ collection: collectionSlug, req, returning, select, where: whereArg }) {
const collection = this.payload.collections[collectionSlug].config;
const tableName = this.tableNameMap.get(toSnakeCase(collection.slug));
let docToDelete;
const { joins, selectFields, where } = buildQuery({
adapter: this,
fields: collection.flattenedFields,
locale: req?.locale,
tableName,
where: whereArg
});
const db = await getTransaction(this, req);
const selectDistinctResult = await selectDistinct({
adapter: this,
db,
joins,
query: ({ query })=>query.limit(1),
selectFields,
tableName,
where
});
if (selectDistinctResult?.[0]?.id) {
docToDelete = await db.query[tableName].findFirst({
where: eq(this.tables[tableName].id, selectDistinctResult[0].id)
});
} else {
const findManyArgs = buildFindManyArgs({
adapter: this,
depth: 0,
fields: collection.flattenedFields,
joinQuery: false,
select,
tableName
});
findManyArgs.where = where;
docToDelete = await db.query[tableName].findFirst(findManyArgs);
}
if (!docToDelete) {
return null;
}
const result = returning === false ? null : transform({
adapter: this,
config: this.payload.config,
data: docToDelete,
fields: collection.flattenedFields,
joinQuery: false,
tableName
});
await this.deleteWhere({
db,
tableName,
where: eq(this.tables[tableName].id, docToDelete.id)
});
return result;
};
//# sourceMappingURL=deleteOne.js.map