fix: bulk publish (#6007)
This commit is contained in:
@@ -275,7 +275,7 @@ export const updateOperation = async <TSlug extends keyof GeneratedTypes['collec
|
|||||||
// Update
|
// Update
|
||||||
// /////////////////////////////////////
|
// /////////////////////////////////////
|
||||||
|
|
||||||
if (!shouldSaveDraft) {
|
if (!shouldSaveDraft || data._status === 'published') {
|
||||||
result = await req.payload.db.updateOne({
|
result = await req.payload.db.updateOne({
|
||||||
id,
|
id,
|
||||||
collection: collectionConfig.slug,
|
collection: collectionConfig.slug,
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ export const updateByIDOperation = async <TSlug extends keyof GeneratedTypes['co
|
|||||||
// Update
|
// Update
|
||||||
// /////////////////////////////////////
|
// /////////////////////////////////////
|
||||||
|
|
||||||
if (!shouldSaveDraft) {
|
if (!shouldSaveDraft || data._status === 'published') {
|
||||||
result = await req.payload.db.updateOne({
|
result = await req.payload.db.updateOne({
|
||||||
id,
|
id,
|
||||||
collection: collectionConfig.slug,
|
collection: collectionConfig.slug,
|
||||||
|
|||||||
@@ -440,6 +440,7 @@ describe('Versions', () => {
|
|||||||
collection,
|
collection,
|
||||||
data: {
|
data: {
|
||||||
title: patchedTitle,
|
title: patchedTitle,
|
||||||
|
_status: 'draft',
|
||||||
},
|
},
|
||||||
draft: true,
|
draft: true,
|
||||||
locale: 'en',
|
locale: 'en',
|
||||||
@@ -453,6 +454,7 @@ describe('Versions', () => {
|
|||||||
collection,
|
collection,
|
||||||
data: {
|
data: {
|
||||||
title: spanishTitle,
|
title: spanishTitle,
|
||||||
|
_status: 'draft',
|
||||||
},
|
},
|
||||||
draft: true,
|
draft: true,
|
||||||
locale: 'es',
|
locale: 'es',
|
||||||
@@ -532,9 +534,11 @@ describe('Versions', () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// bulk publish
|
||||||
const updated = await payload.update({
|
const updated = await payload.update({
|
||||||
collection: draftCollectionSlug,
|
collection: draftCollectionSlug,
|
||||||
data: {
|
data: {
|
||||||
|
_status: 'published',
|
||||||
description: 'updated description',
|
description: 'updated description',
|
||||||
},
|
},
|
||||||
draft: true,
|
draft: true,
|
||||||
@@ -547,8 +551,20 @@ describe('Versions', () => {
|
|||||||
|
|
||||||
const updatedDoc = updated.docs?.[0]
|
const updatedDoc = updated.docs?.[0]
|
||||||
|
|
||||||
|
// get the published doc
|
||||||
|
const findResult = await payload.find({
|
||||||
|
collection: draftCollectionSlug,
|
||||||
|
where: {
|
||||||
|
id: { equals: doc.id },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const findDoc = findResult.docs?.[0]
|
||||||
|
|
||||||
expect(updatedDoc.description).toStrictEqual('updated description')
|
expect(updatedDoc.description).toStrictEqual('updated description')
|
||||||
expect(updatedDoc.title).toStrictEqual('updated title') // probably will fail
|
expect(updatedDoc.title).toStrictEqual('updated title')
|
||||||
|
expect(findDoc.title).toStrictEqual('updated title')
|
||||||
|
expect(findDoc.description).toStrictEqual('updated description')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -1302,6 +1318,7 @@ describe('Versions', () => {
|
|||||||
await payload.updateGlobal({
|
await payload.updateGlobal({
|
||||||
slug: globalSlug,
|
slug: globalSlug,
|
||||||
data: {
|
data: {
|
||||||
|
_status: 'draft',
|
||||||
title: updatedTitle2,
|
title: updatedTitle2,
|
||||||
},
|
},
|
||||||
draft: true,
|
draft: true,
|
||||||
@@ -1311,6 +1328,7 @@ describe('Versions', () => {
|
|||||||
await payload.updateGlobal({
|
await payload.updateGlobal({
|
||||||
slug: globalSlug,
|
slug: globalSlug,
|
||||||
data: {
|
data: {
|
||||||
|
_status: 'draft',
|
||||||
title: updatedTitle2,
|
title: updatedTitle2,
|
||||||
},
|
},
|
||||||
draft: true,
|
draft: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user