Skip to content

Commit

Permalink
Merge pull request #319 from kellnerd/approve-import
Browse files Browse the repository at this point in the history
Make approval of imported entities work
  • Loading branch information
MonkeyDo committed Jul 17, 2024
2 parents 891336a + 817ec3f commit 98f6ade
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/func/create-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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'),
Expand All @@ -145,5 +148,5 @@ export async function createEntity({
withRelated: ['defaultAlias']
});

return entity.toJSON();
return entity;
}
10 changes: 7 additions & 3 deletions src/func/imports/approve-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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')
Expand All @@ -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;
}

0 comments on commit 98f6ade

Please sign in to comment.