Merge pull request #1451 from jacobsfletch/fix/draft-patch

fix: ensures draft operations save as drafts
This commit is contained in:
Jacob Fletcher
2022-11-21 15:15:52 -05:00
committed by GitHub
5 changed files with 96 additions and 7 deletions

View File

@@ -21,6 +21,8 @@ export const saveCollectionDraft = async ({
}: Args): Promise<Record<string, unknown>> => {
const VersionsModel = payload.versions[config.slug];
const dataAsDraft = { ...data, _status: 'draft' };
let existingAutosaveVersion;
if (autosave) {
@@ -40,7 +42,7 @@ export const saveCollectionDraft = async ({
_id: existingAutosaveVersion._id,
},
{
version: data,
version: dataAsDraft,
},
{ new: true, lean: true },
);
@@ -48,7 +50,7 @@ export const saveCollectionDraft = async ({
} else {
result = await VersionsModel.create({
parent: id,
version: data,
version: dataAsDraft,
autosave: Boolean(autosave),
});
}

View File

@@ -17,6 +17,8 @@ export const saveGlobalDraft = async ({
}: Args): Promise<void> => {
const VersionsModel = payload.versions[config.slug];
const dataAsDraft = { ...data, _status: 'draft' };
let existingAutosaveVersion;
if (autosave) {
@@ -34,14 +36,14 @@ export const saveGlobalDraft = async ({
_id: existingAutosaveVersion._id,
},
{
version: data,
version: dataAsDraft,
},
{ new: true, lean: true },
);
// Otherwise, create a new one
} else {
result = await VersionsModel.create({
version: data,
version: dataAsDraft,
autosave: Boolean(autosave),
});
}

View File

@@ -51,6 +51,7 @@ export const ensurePublishedCollectionVersion = async ({
req,
overrideAccess: true,
showHiddenFields: true,
flattenLocales: false,
});
try {

View File

@@ -46,6 +46,7 @@ export const ensurePublishedGlobalVersion = async ({
req,
overrideAccess: true,
showHiddenFields: true,
flattenLocales: false,
});
try {