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
38 lines
1.2 KiB
Plaintext
38 lines
1.2 KiB
Plaintext
import { deepCopyObjectSimple } from '../index.js';
|
|
import { getQueryDraftsSelect } from './drafts/getQueryDraftsSelect.js';
|
|
export const saveSnapshot = async ({ id, autosave, collection, data, global, payload, publishSpecificLocale, req, select })=>{
|
|
const docData = deepCopyObjectSimple(data || {});
|
|
if (docData._id) {
|
|
delete docData._id;
|
|
}
|
|
const snapshotDate = new Date().toISOString();
|
|
const sharedCreateVersionArgs = {
|
|
autosave: Boolean(autosave),
|
|
createdAt: snapshotDate,
|
|
publishedLocale: publishSpecificLocale || undefined,
|
|
req,
|
|
returning: false,
|
|
select: getQueryDraftsSelect({
|
|
select
|
|
}),
|
|
updatedAt: snapshotDate,
|
|
versionData: docData
|
|
};
|
|
if (collection && id) {
|
|
return payload.db.createVersion({
|
|
...sharedCreateVersionArgs,
|
|
collectionSlug: collection.slug,
|
|
parent: id,
|
|
snapshot: true
|
|
});
|
|
}
|
|
if (global) {
|
|
return payload.db.createGlobalVersion({
|
|
...sharedCreateVersionArgs,
|
|
globalSlug: global.slug,
|
|
snapshot: true
|
|
});
|
|
}
|
|
};
|
|
|
|
//# sourceMappingURL=saveSnapshot.js.map |