Skip to content

Commit

Permalink
apply coordinator fix to other team types.
Browse files Browse the repository at this point in the history
  • Loading branch information
devinleighsmith committed Nov 22, 2023
1 parent 4593ebd commit e6a1328
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { useDocumentGenerationRepository } from '@/features/documents/hooks/useD
import { FormTemplateTypes } from '@/features/mapSideBar/shared/content/models';
import { useApiContacts } from '@/hooks/pims-api/useApiContacts';
import { useAcquisitionProvider } from '@/hooks/repositories/useAcquisitionProvider';
import { Api_AcquisitionFileTeam } from '@/models/api/AcquisitionFile';
import { AgreementTypes, Api_Agreement } from '@/models/api/Agreement';
import { ExternalResultStatus } from '@/models/api/ExternalResult';
import { Api_Organization } from '@/models/api/Organization';
import { Api_GenerateAcquisitionFile } from '@/models/generate/acquisition/GenerateAcquisitionFile';
import { Api_GenerateAgreement } from '@/models/generate/GenerateAgreement';

Expand Down Expand Up @@ -40,20 +42,15 @@ export const useGenerateAgreement = () => {
const coordinatorPromise = coordinator?.personId
? getPersonConcept(coordinator?.personId).then(p => (coordinator.person = p?.data))
: coordinator?.organizationId
? getOrganizationConcept(coordinator?.organizationId).then(o => {
if (!!coordinator) {
coordinator.organization = o?.data;
coordinator.primaryContact =
o?.data?.organizationPersons?.find(op => op.personId === coordinator.primaryContactId)
?.person ?? coordinator.primaryContact;
}
})
? getOrganizationConcept(coordinator?.organizationId).then(o =>
!!coordinator ? setOrganization(coordinator, o?.data) : null,
)
: Promise.resolve();
const negotiatingAgentPromise = negotiatingAgent?.personId
? getPersonConcept(negotiatingAgent?.personId).then(p => (negotiatingAgent.person = p?.data))
: negotiatingAgent?.organizationId
? getOrganizationConcept(negotiatingAgent?.organizationId).then(o =>
!!negotiatingAgent ? (negotiatingAgent.organization = o?.data) : null,
!!negotiatingAgent ? setOrganization(negotiatingAgent, o?.data) : null,
)
: Promise.resolve();
const provincialSolicitorPromise = provincialSolicitor?.personId
Expand All @@ -62,7 +59,7 @@ export const useGenerateAgreement = () => {
)
: provincialSolicitor?.organizationId
? getOrganizationConcept(provincialSolicitor?.organizationId).then(o =>
!!provincialSolicitor ? (provincialSolicitor.organization = o?.data) : null,
!!provincialSolicitor ? setOrganization(provincialSolicitor, o?.data) : null,

Check warning on line 62 in source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.ts

View check run for this annotation

Codecov / codecov/patch

source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.ts#L62

Added line #L62 was not covered by tests
)
: Promise.resolve();

Expand Down Expand Up @@ -130,3 +127,12 @@ const getTemplateTypeFromAgreementType = (agreementType: string) => {
throw Error(`Unable to find form type for agreement type: ${agreementType}`);
}
};

const setOrganization = (team: Api_AcquisitionFileTeam, organization: Api_Organization) => {
if (!!team) {
team.organization = organization;
team.primaryContact =
organization?.organizationPersons?.find(op => op.personId === team.primaryContactId)
?.person ?? team.primaryContact;
}
};

0 comments on commit e6a1328

Please sign in to comment.