From b978ae88379ea07db147c41e017690ea6b283a3c Mon Sep 17 00:00:00 2001 From: David Kellner <52860029+kellnerd@users.noreply.github.com> Date: Wed, 17 Jul 2024 23:12:48 +0200 Subject: [PATCH] fix(imports): Set revision of an imported annotation on approval --- src/func/imports/approve-import.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/func/imports/approve-import.ts b/src/func/imports/approve-import.ts index fe9b4db6..ead659a4 100644 --- a/src/func/imports/approve-import.ts +++ b/src/func/imports/approve-import.ts @@ -48,16 +48,20 @@ export async function approveImport( incrementEditorEditCountById(orm, editorId, transacting); // Create a new revision record - const revisionPromise = new Revision({ + const revision = await new Revision({ authorId: editorId }).save(null, {transacting}); + const revisionId = revision.get('id'); + + if (annotationId) { + // Set revision of our annotation which is NULL for imports + await new orm.Annotation({id: annotationId}) + .save({lastRevisionId: revisionId}, {transacting}); + } const note = `Approved from automatically imported record of ${source}`; // Create a new note promise - const notePromise = revisionPromise - .then((revision) => createNote( - orm, note, editorId, revision, transacting - )); + const notePromise = createNote(orm, note, editorId, revision, transacting); // Get additional props const additionalProps = getAdditionalEntityProps(importEntity, entityType); @@ -70,9 +74,7 @@ export async function approveImport( , {} ); - const [revisionRecord] = await Promise.all([ - revisionPromise, notePromise, editorUpdatePromise - ]); + await Promise.all([notePromise, editorUpdatePromise]); const newEntity = await new Entity({type: entityType}) .save(null, {transacting}); @@ -83,7 +85,7 @@ export async function approveImport( bbid, disambiguationId, identifierSetId, - revisionId: revisionRecord && revisionRecord.get('id') + revisionId }, entitySets, additionalProps); const Model = getEntityModelByType(orm, entityType);