Skip to content

Commit

Permalink
HPC-9142: Refactor getAndValidateAllPlanEntities
Browse files Browse the repository at this point in the history
Removed entitiesAssociation usage
  • Loading branch information
enxtur committed May 17, 2024
1 parent 0e47bc1 commit 4e52ea1
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions src/lib/data/planEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,6 @@ export const getAndValidateAllPlanEntities = async ({
'planEntityId'
);

const eaByChildId = await findAndOrganizeObjectsByUniqueProperty(
database.entitiesAssociation,
(t) =>
t.find({
where: {
childType: 'planEntity',
parentType: 'governingEntity',
childId: {
[Op.IN]: planEntityIDs,
},
},
}),
'childId'
);

const result: ValidatedPlanEntities = annotatedMap('planEntity');

for (const planEntity of planEntities) {
Expand All @@ -133,7 +118,6 @@ export const getAndValidateAllPlanEntities = async ({
planEntity,
planEntityVersion,
prototypes,
entityAssociations: eaByChildId,
governingEntities,
});

Expand All @@ -143,7 +127,7 @@ export const getAndValidateAllPlanEntities = async ({
customRef: refAndType.customRef,
description: null,
supports: [],
governingEntity: eaByChildId.get(planEntity.id)?.parentId ?? null,
governingEntity: planEntity.parentGoverningEntityId,
};

// Use entity details if possible
Expand Down Expand Up @@ -219,7 +203,6 @@ const getCustomReferenceAndTypeForPlanEntity = ({
planEntity,
planEntityVersion,
prototypes,
entityAssociations,
governingEntities,
}: {
planEntity: InstanceDataOfModel<Database['planEntity']>;
Expand All @@ -233,14 +216,6 @@ const getCustomReferenceAndTypeForPlanEntity = ({
EntityPrototypeId,
InstanceDataOfModel<Database['entityPrototype']>
>;
/**
* A map of associations from the `entitiesAssociation` table, that **must**
* include any rows that reference this entity.
*/
entityAssociations: Map<
PlanEntityId,
InstanceDataOfModel<Database['entitiesAssociation']>
>;
/**
* A map from governing entity IDs to an object containing the .
*
Expand All @@ -257,13 +232,12 @@ const getCustomReferenceAndTypeForPlanEntity = ({
planEntity,
'entityPrototypeId'
);
const parent = entityAssociations.get(planEntity.id);
let ref = '';
if (parent) {
if (planEntity.parentGoverningEntityId) {
const ge = getRequiredDataByValue(
governingEntities,
planEntity,
() => parent.parentId
(pE) => pE.parentGoverningEntityId
);
ref = `${ge.customRef}/`;
}
Expand Down

0 comments on commit 4e52ea1

Please sign in to comment.