diff --git a/src/func/create-entity.ts b/src/func/create-entity.ts index e194d87d..d17fcbb1 100644 --- a/src/func/create-entity.ts +++ b/src/func/create-entity.ts @@ -58,11 +58,11 @@ interface CreateEntityPropsType { entityType: EntityTypeString } -// TODO: function seems to be unused across all BB repos, ignore its errors (and delete it?) +// TODO: function is only used to approve imports, check whether type error below is critical export async function createEntity({ editorId, entityData, orm, transacting }: CreateEntityPropsType) { - const {Revision} = orm; + const {Entity, Revision} = orm; const {aliases, annotation, disambiguation, identifiers, note, type: entityType, ...entitySetData} = entityData; @@ -105,7 +105,7 @@ export async function createEntity({ ); // Get additional props - // @ts-expect-error Not sure why we have this error but this whole function is unused across our repos + // @ts-expect-error Not sure why we have this error const additionalProps = getAdditionalEntityProps(entityData, entityType); // Create entitySets @@ -123,9 +123,12 @@ export async function createEntity({ editorUpdatePromise, notePromise ]); + const newEntity = await new Entity({type: entityType}) + .save(null, {transacting}); const propsToSet = _.extend({ aliasSetId: aliasSetRecord && aliasSetRecord.get('id'), annotationId: annotationRecord && annotationRecord.get('id'), + bbid: newEntity.get('bbid'), disambiguationId: disambiguationRecord && disambiguationRecord.get('id'), identifierSetId: identSetRecord && identSetRecord.get('id'), @@ -145,5 +148,5 @@ export async function createEntity({ withRelated: ['defaultAlias'] }); - return entity.toJSON(); + return entity; } diff --git a/src/func/imports/approve-import.ts b/src/func/imports/approve-import.ts index c55f84b0..0a58f79e 100644 --- a/src/func/imports/approve-import.ts +++ b/src/func/imports/approve-import.ts @@ -41,7 +41,7 @@ export async function approveImport( identifierSetId} = importEntity; const {id: aliasSetId} = aliasSet; - const {Revision} = orm; + const {Entity, Revision} = orm; // Increase user edit count const editorUpdatePromise = @@ -74,8 +74,12 @@ export async function approveImport( revisionPromise, notePromise, editorUpdatePromise ]); + const newEntity = await new Entity({type: entityType}) + .save(null, {transacting}); + const bbid = newEntity.get('bbid'); const propsToSet = _.extend({ aliasSetId, + bbid, disambiguationId, identifierSetId, revisionId: revisionRecord && revisionRecord.get('id') @@ -92,9 +96,9 @@ export async function approveImport( const entity = await entityModel.refresh({ transacting, withRelated: ['defaultAlias'] - }).then(entityObject => entityObject.toJSON()); + }); - await deleteImport(transacting, importId, entity.bbid); + await deleteImport(transacting, importId, bbid); return entity; }