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
33 lines
1.1 KiB
Plaintext
33 lines
1.1 KiB
Plaintext
import toSnakeCase from 'to-snake-case';
|
|
import { upsertRow } from './upsertRow/index.js';
|
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
export async function updateGlobal({ slug, data, req, returning, select }) {
|
|
const globalConfig = this.payload.globals.config.find((config)=>config.slug === slug);
|
|
const tableName = this.tableNameMap.get(toSnakeCase(globalConfig.slug));
|
|
const db = await getTransaction(this, req);
|
|
const existingGlobal = await db.query[tableName].findFirst({});
|
|
const result = await upsertRow({
|
|
...existingGlobal ? {
|
|
id: existingGlobal.id,
|
|
operation: 'update'
|
|
} : {
|
|
operation: 'create'
|
|
},
|
|
adapter: this,
|
|
data,
|
|
db,
|
|
fields: globalConfig.flattenedFields,
|
|
globalSlug: slug,
|
|
ignoreResult: returning === false,
|
|
req,
|
|
select,
|
|
tableName
|
|
});
|
|
if (returning === false) {
|
|
return null;
|
|
}
|
|
result.globalType = slug;
|
|
return result;
|
|
}
|
|
|
|
//# sourceMappingURL=updateGlobal.js.map |