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

HPC-9142: Remove entitiesAssociation model and its usages #147

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import emergency from './models/emergency';
import emergencyLocation from './models/emergencyLocation';
import endpointLog from './models/endpointLog';
import endpointUsage from './models/endpointUsage';
import entitiesAssociation from './models/entitiesAssociation';
import entityPrototype from './models/entityPrototype';
import expiredData from './models/expiredData';
import externalData from './models/externalData';
Expand Down Expand Up @@ -141,7 +140,6 @@ const initializeTables = (conn: Knex) => ({
emergencyLocation: emergencyLocation(conn),
endpointLog: endpointLog(conn),
endpointUsage: endpointUsage(conn),
entitiesAssociation: entitiesAssociation(conn),
entityPrototype: entityPrototype(conn),
expiredData: expiredData(conn),
externalData: externalData(conn),
Expand Down
17 changes: 0 additions & 17 deletions src/db/models/entitiesAssociation.ts

This file was deleted.

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