Skip to content

Commit

Permalink
Unrevert Tweak taxonomy mappings for KHP imports
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhand committed Nov 6, 2024
1 parent 43f9a22 commit ee1dc45
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions resources-domain/lambdas/import-producer/src/khpMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,10 @@ const KHP_MAPPING_NODE_SITES: { children: MappingNode } = {
},
};

const MAX_TAXONOMY_DEPTH = 5;

// TODO: this is an array of arrays, is this shape correct?
const KHP_MAPPING_NODE_TAXONOMIES: { children: MappingNode } = {
const KHP_MAPPING_NODE_TAXONOMIES = (depth: number = 0): { children: MappingNode } => ({
children: {
'{taxonomyIndex}': {
children: {
Expand All @@ -272,6 +274,10 @@ const KHP_MAPPING_NODE_TAXONOMIES: { children: MappingNode } = {
info: ctx => ctx.parentValue,
},
),
...(depth + 1 <= MAX_TAXONOMY_DEPTH
? { ancestors: KHP_MAPPING_NODE_TAXONOMIES(depth + 1) }
: {}),
// Deprecated
ancestorTaxonomies: {
children: {
'{ancestorIndex}': {
Expand Down Expand Up @@ -299,15 +305,20 @@ const KHP_MAPPING_NODE_TAXONOMIES: { children: MappingNode } = {
},
},
},
};
});

export const KHP_MAPPING_NODE: MappingNode = {
_id: resourceFieldMapping('id'),
// TODO: Remove this and all other 'objectId' mappings once the updated Arctic API is deployed to production
objectId: resourceFieldMapping('id'),
timeSequence: resourceFieldMapping('importSequenceId'),
sites: KHP_MAPPING_NODE_SITES,
taxonomies: KHP_MAPPING_NODE_TAXONOMIES,
taxonomies: {
...KHP_MAPPING_NODE_TAXONOMIES(),
children: {
'{topIndex}': KHP_MAPPING_NODE_TAXONOMIES(),
},
},
name: resourceFieldMapping('name', ctx => ctx.currentValue.en || ctx.currentValue.fr),
updatedAt: resourceFieldMapping('lastUpdated'),
createdAt: attributeMapping('dateTimeAttributes', 'sourceCreatedAt'),
Expand Down Expand Up @@ -677,13 +688,14 @@ export const KHP_MAPPING_NODE: MappingNode = {
children: {
objectId: { children: {} },
_id: { children: {} },
__v: {},
name: {},
'{language}': referenceAttributeMapping(
'feeStructure/{feeStructureSourceIndex}',
'khp-fee-structure-source',
{
value: ctx => ctx.parentValue.en,
value: ctx => ctx.parentValue[ctx.captures.language],
language: ctx => ctx.captures.language,
// value: ctx => ctx.currentValue.en || ctx.currentValue.fr,
},
),
},
Expand All @@ -695,6 +707,10 @@ export const KHP_MAPPING_NODE: MappingNode = {
children: {
'{howIsServiceOfferedIndex}': {
children: {
objectId: { children: {} },
_id: { children: {} },
__v: {},
name: {},
'{language}': referenceAttributeMapping(
'howIsServiceOffered/{howIsServiceOfferedIndex}',
'khp-how-is-service-offered',
Expand Down

0 comments on commit ee1dc45

Please sign in to comment.