From 4a97b35d5a61f5e924f5c6084a212c544f90036a Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 11 Jan 2023 20:56:14 -0500 Subject: [PATCH] fix: Collection structure update on document move --- server/commands/documentMover.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/server/commands/documentMover.ts b/server/commands/documentMover.ts index 36f038821..6f8ed56e6 100644 --- a/server/commands/documentMover.ts +++ b/server/commands/documentMover.ts @@ -71,6 +71,7 @@ async function documentMover({ // Remove the document from the current collection const response = await collection?.removeDocumentInStructure(document, { transaction, + save: collectionChanged, }); const documentJson = response?.[0]; @@ -92,19 +93,25 @@ async function documentMover({ ? index - 1 : index; + // Update the properties on the document record, this must be done after + // the toIndex is calculated above + document.collectionId = collectionId; + document.parentDocumentId = parentDocumentId; + document.lastModifiedById = user.id; + document.updatedBy = user; + // Add the document and it's tree to the new collection await newCollection.addDocumentToStructure(document, toIndex, { documentJson, transaction, }); + } else { + document.collectionId = collectionId; + document.parentDocumentId = parentDocumentId; + document.lastModifiedById = user.id; + document.updatedBy = user; } - // Update the properties on the document record - document.collectionId = collectionId; - document.parentDocumentId = parentDocumentId; - document.lastModifiedById = user.id; - document.updatedBy = user; - if (collection && document.publishedAt) { result.collections.push(collection); }