fix: Collection structure update on document move

This commit is contained in:
Tom Moor
2023-01-11 20:56:14 -05:00
parent 785b9888dd
commit 4a97b35d5a

View File

@@ -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);
}