Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bulk publish #6006

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/payload/src/collections/operations/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ async function update<TSlug extends keyof GeneratedTypes['collections']>(
// Update
// /////////////////////////////////////

if (!shouldSaveDraft) {
if (!shouldSaveDraft || data._status === 'published') {
result = await req.payload.db.updateOne({
id,
collection: collectionConfig.slug,
Expand Down
2 changes: 1 addition & 1 deletion packages/payload/src/collections/operations/updateByID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ async function updateByID<TSlug extends keyof GeneratedTypes['collections']>(
// Update
// /////////////////////////////////////

if (!shouldSaveDraft) {
if (!shouldSaveDraft || data._status === 'published') {
result = await req.payload.db.updateOne({
id,
collection: collectionConfig.slug,
Expand Down
20 changes: 19 additions & 1 deletion test/versions/int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ describe('Versions', () => {
collection,
data: {
title: patchedTitle,
_status: 'draft',
},
draft: true,
locale: 'en',
Expand All @@ -450,6 +451,7 @@ describe('Versions', () => {
collection,
data: {
title: spanishTitle,
_status: 'draft',
},
draft: true,
locale: 'es',
Expand Down Expand Up @@ -529,9 +531,11 @@ describe('Versions', () => {
},
})

// bulk publish
const updated = await payload.update({
collection: draftCollectionSlug,
data: {
_status: 'published',
description: 'updated description',
},
draft: true,
Expand All @@ -544,8 +548,20 @@ describe('Versions', () => {

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.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')
})
})

Expand Down Expand Up @@ -1236,6 +1252,7 @@ describe('Versions', () => {
await payload.updateGlobal({
slug: globalSlug,
data: {
_status: 'draft',
title: updatedTitle2,
},
draft: true,
Expand All @@ -1245,6 +1262,7 @@ describe('Versions', () => {
await payload.updateGlobal({
slug: globalSlug,
data: {
_status: 'draft',
title: updatedTitle2,
},
draft: true,
Expand Down