Skip to content

Commit

Permalink
fix(imports): Set revision of an imported annotation on approval
Browse files Browse the repository at this point in the history
  • Loading branch information
kellnerd committed Jul 17, 2024
1 parent 110e9f7 commit b978ae8
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/func/imports/approve-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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});
Expand All @@ -83,7 +85,7 @@ export async function approveImport(
bbid,
disambiguationId,
identifierSetId,
revisionId: revisionRecord && revisionRecord.get('id')
revisionId
}, entitySets, additionalProps);

const Model = getEntityModelByType(orm, entityType);
Expand Down

0 comments on commit b978ae8

Please sign in to comment.