Skip to content

Commit

Permalink
Merge pull request #213 from UN-OCHA/after-codec-cleanup
Browse files Browse the repository at this point in the history
Simplify code after cleaning up `support` array of `planEntityVersion` codec
  • Loading branch information
Pl217 authored Jan 24, 2025
2 parents 829a54f + ce84fcd commit 2586826
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@unocha/hpc-api-core",
"version": "10.8.1",
"version": "10.9.0",
"description": "Core libraries supporting HPC.Tools API Backend",
"license": "Apache-2.0",
"private": false,
Expand Down
38 changes: 16 additions & 22 deletions src/lib/data/planEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
annotatedMap,
getRequiredData,
getRequiredDataByValue,
isDefined,
type AnnotatedMap,
} from '../../util';
import type { MapOfGoverningEntities } from './governingEntities';
Expand Down Expand Up @@ -135,29 +134,24 @@ export const getAndValidateAllPlanEntities = async ({
// Able to inspect entity details
entityDetails.description = planEntityVersion.value.description;

if (
planEntityVersion.value.support &&
Array.isArray(planEntityVersion.value.support)
) {
const supportingPlanEntityIds = planEntityVersion.value.support
.flatMap((s) => s?.planEntityIds)
.filter(isDefined);
// Check that the list of planEntityIds is valid
const missing = supportingPlanEntityIds.filter(
(id) => !planEntityIDs.has(id)
);
if (!allowMissingPlanEntities && missing.length > 0) {
throw new Error(
`Missing supporting planEntityIds: ${missing.join(', ')}`
);
}

// TODO: Check that the plan entities pass the canSupport requirements
// specified in the prototype, including matching the cardinality
entityDetails.supports = supportingPlanEntityIds.filter((id) =>
planEntityIDs.has(id)
const supportingPlanEntityIds = planEntityVersion.value.support.flatMap(
(s) => s.planEntityIds ?? []
);
// Check that the list of planEntityIds is valid
const missing = supportingPlanEntityIds.filter(
(id) => !planEntityIDs.has(id)
);
if (!allowMissingPlanEntities && missing.length > 0) {
throw new Error(
`Missing supporting planEntityIds: ${missing.join(', ')}`
);
}

// TODO: Check that the plan entities pass the canSupport requirements
// specified in the prototype, including matching the cardinality
entityDetails.supports = supportingPlanEntityIds.filter((id) =>
planEntityIDs.has(id)
);
}

result.set(entityDetails.id, entityDetails);
Expand Down

0 comments on commit 2586826

Please sign in to comment.