Skip to content

Commit

Permalink
Include group codename in taxonomy term external ids to make the unique
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriLojda committed Feb 1, 2024
1 parent 6ffa438 commit 6f88889
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/commands/importExportEntities/entities/taxonomies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const taxonomiesEntity: EntityDefinition<ReadonlyArray<TaxonomyContracts.

return client
.addTaxonomy()
.withData(addExternalIds(taxonomy))
.withData(createAddExternalIds(taxonomy)(taxonomy))
.toPromise()
.then(res => res.data._raw);
}),
Expand All @@ -36,11 +36,14 @@ export const taxonomiesEntity: EntityDefinition<ReadonlyArray<TaxonomyContracts.
deserializeEntities: JSON.parse,
};

const addExternalIds = (taxonomy: TaxonomyContracts.ITaxonomyContract): TaxonomyContracts.ITaxonomyContract => ({
...taxonomy,
external_id: taxonomy.external_id ?? taxonomy.codename,
terms: taxonomy.terms.map(addExternalIds),
});
const createAddExternalIds =
(group: TaxonomyContracts.ITaxonomyContract) =>
(taxonomy: TaxonomyContracts.ITaxonomyContract): TaxonomyContracts.ITaxonomyContract => ({
...taxonomy,
external_id: taxonomy.external_id
?? (taxonomy === group ? group.codename : `${group.codename}_${taxonomy.codename}`),
terms: taxonomy.terms.map(createAddExternalIds(group)),
});

const extractTermIdsEntries = (
[fileTaxonomy, projectTaxonomy]: readonly [TaxonomyContracts.ITaxonomyContract, TaxonomyContracts.ITaxonomyContract],
Expand Down

0 comments on commit 6f88889

Please sign in to comment.