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

V1.19 rc merge #776

Merged
merged 8 commits into from
Nov 11, 2024
17 changes: 14 additions & 3 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