Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make approval of imported entities work #319

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading