From becfb1c570d1e95e31ebdb933ab5fd05042e4d3a Mon Sep 17 00:00:00 2001 From: devinleighsmith Date: Mon, 30 Oct 2023 15:38:44 -0700 Subject: [PATCH] psp-6991 update agreement generation to support team organizations. --- .../hooks/useGenerateAgreement.ts | 51 ++++++++++--------- .../GenerateForm/hooks/useGenerateLetter.ts | 14 +++-- .../src/models/generate/GenerateLetter.ts | 8 +-- .../acquisition/GenerateAcquisitionFile.ts | 42 +++++++++++---- 4 files changed, 72 insertions(+), 43 deletions(-) diff --git a/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.ts b/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.ts index cc75d840e6..746cdfc696 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.ts +++ b/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateAgreement.ts @@ -38,14 +38,28 @@ export const useGenerateAgreement = () => { ); const coordinatorPromise = coordinator?.personId - ? getPersonConcept(coordinator?.personId) - : Promise.resolve(null); + ? getPersonConcept(coordinator?.personId).then(p => (coordinator.person = p?.data)) + : provincialSolicitor?.organizationId + ? getOrganizationConcept(provincialSolicitor?.organizationId).then(o => + !!coordinator ? (coordinator.organization = o?.data) : null, + ) + : Promise.resolve(); const negotiatingAgentPromise = negotiatingAgent?.personId - ? getPersonConcept(negotiatingAgent?.personId) - : Promise.resolve(null); + ? getPersonConcept(negotiatingAgent?.personId).then(p => (negotiatingAgent.person = p?.data)) + : provincialSolicitor?.organizationId + ? getOrganizationConcept(provincialSolicitor?.organizationId).then(o => + !!negotiatingAgent ? (negotiatingAgent.organization = o?.data) : null, + ) + : Promise.resolve(); const provincialSolicitorPromise = provincialSolicitor?.personId - ? getPersonConcept(provincialSolicitor?.personId) - : Promise.resolve(null); + ? getPersonConcept(provincialSolicitor?.personId).then( + p => (provincialSolicitor.person = p?.data), + ) + : provincialSolicitor?.organizationId + ? getOrganizationConcept(provincialSolicitor?.organizationId).then(o => + !!provincialSolicitor ? (provincialSolicitor.organization = o?.data) : null, + ) + : Promise.resolve(); // Owner solicitor can be either a Person or an Organization (with optional primary contact) const ownerSolicitorPersonPromise = ownerSolicitor?.personId @@ -59,21 +73,10 @@ export const useGenerateAgreement = () => { ? getPersonConcept(ownerSolicitor?.primaryContactId) : Promise.resolve(null); - const [ - coordinatorConcept, - negotiatingAgentConcept, - provincialSolicitorConcept, - ownerSolicitorPersonConcept, - ownerSolicitorOrganizationConcept, - ownerSolicitorPrimaryContactConcept, - ] = await Promise.all([ - coordinatorPromise, - negotiatingAgentPromise, - provincialSolicitorPromise, - ownerSolicitorPersonPromise, - ownerSolicitorOrganizationPromise, - ownerSolicitorPrimaryContactPromise, - ]); + await Promise.all([coordinatorPromise, negotiatingAgentPromise, provincialSolicitorPromise]); + const ownerSolicitorPersonConcept = await ownerSolicitorPersonPromise; + const ownerSolicitorOrganizationConcept = await ownerSolicitorOrganizationPromise; + const ownerSolicitorPrimaryContactConcept = await ownerSolicitorPrimaryContactPromise; if (ownerSolicitor) { ownerSolicitor.person = ownerSolicitorPersonConcept?.data ?? null; @@ -83,9 +86,9 @@ export const useGenerateAgreement = () => { const fileData = new Api_GenerateAcquisitionFile({ file, - coordinatorContact: coordinatorConcept?.data ?? null, - negotiatingAgent: negotiatingAgentConcept?.data ?? null, - provincialSolicitor: provincialSolicitorConcept?.data ?? null, + coordinatorContact: coordinator ?? null, + negotiatingAgent: negotiatingAgent ?? null, + provincialSolicitor: provincialSolicitor ?? null, ownerSolicitor: ownerSolicitor ?? null, interestHolders: [], }); diff --git a/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateLetter.ts b/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateLetter.ts index 9de9e1cd31..342e0edf14 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateLetter.ts +++ b/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateLetter.ts @@ -8,7 +8,7 @@ import { Api_GenerateLetter } from '@/models/generate/GenerateLetter'; import { Api_GenerateOwner } from '@/models/generate/GenerateOwner'; export const useGenerateLetter = () => { - const { getPersonConcept } = useApiContacts(); + const { getPersonConcept, getOrganizationConcept } = useApiContacts(); const { getAcquisitionFile: { execute: getAcquisitionFile }, } = useAcquisitionProvider(); @@ -24,10 +24,14 @@ export const useGenerateLetter = () => { const coordinator = file.acquisitionTeam?.find( team => team.teamProfileTypeCode === 'PROPCOORD', ); - const coordinatorPerson = !!coordinator?.personId - ? (await getPersonConcept(coordinator?.personId))?.data - : null; - const letterData = new Api_GenerateLetter(file, coordinatorPerson); + if (!!coordinator?.personId) { + coordinator.person = (await getPersonConcept(coordinator?.personId))?.data; + } else if (!!coordinator?.organizationId) { + coordinator.organization = ( + await getOrganizationConcept(coordinator?.organizationId) + )?.data; + } + const letterData = new Api_GenerateLetter(file, coordinator); letterData.owners = recipients ?? letterData.owners; const generatedFile = await generate({ templateType: FormDocumentType.LETTER, diff --git a/source/frontend/src/models/generate/GenerateLetter.ts b/source/frontend/src/models/generate/GenerateLetter.ts index 84f09491ba..73e1f79328 100644 --- a/source/frontend/src/models/generate/GenerateLetter.ts +++ b/source/frontend/src/models/generate/GenerateLetter.ts @@ -1,12 +1,14 @@ import moment from 'moment'; -import { Api_AcquisitionFile } from '@/models/api/AcquisitionFile'; -import { Api_Person } from '@/models/api/Person'; +import { Api_AcquisitionFile, Api_AcquisitionFileTeam } from '@/models/api/AcquisitionFile'; import { Api_GenerateAcquisitionFile } from './acquisition/GenerateAcquisitionFile'; export class Api_GenerateLetter extends Api_GenerateAcquisitionFile { date_generated: string; - constructor(file: Api_AcquisitionFile, coordinatorContact: Api_Person | null | undefined) { + constructor( + file: Api_AcquisitionFile, + coordinatorContact: Api_AcquisitionFileTeam | null | undefined, + ) { super({ file, coordinatorContact: coordinatorContact ?? null, diff --git a/source/frontend/src/models/generate/acquisition/GenerateAcquisitionFile.ts b/source/frontend/src/models/generate/acquisition/GenerateAcquisitionFile.ts index c477f40f5c..a1e4129dd3 100644 --- a/source/frontend/src/models/generate/acquisition/GenerateAcquisitionFile.ts +++ b/source/frontend/src/models/generate/acquisition/GenerateAcquisitionFile.ts @@ -1,7 +1,7 @@ -import { Api_AcquisitionFile } from '@/models/api/AcquisitionFile'; +import { Api_AcquisitionFile, Api_AcquisitionFileTeam } from '@/models/api/AcquisitionFile'; import { Api_InterestHolder, Api_InterestHolderProperty } from '@/models/api/InterestHolder'; -import { Api_Person } from '@/models/api/Person'; +import { Api_GenerateOrganization } from '../GenerateOrganization'; import { Api_GenerateOwner } from '../GenerateOwner'; import { Api_GeneratePerson } from '../GeneratePerson'; import { Api_GenerateProduct } from '../GenerateProduct'; @@ -12,16 +12,16 @@ import { Api_GenerateInterestHolder } from './GenerateInterestHolder'; export interface IApiGenerateAcquisitionFileInput { file: Api_AcquisitionFile | null; - coordinatorContact?: Api_Person | null; - negotiatingAgent?: Api_Person | null; - provincialSolicitor?: Api_Person | null; + coordinatorContact?: Api_AcquisitionFileTeam | null; + negotiatingAgent?: Api_AcquisitionFileTeam | null; + provincialSolicitor?: Api_AcquisitionFileTeam | null; ownerSolicitor?: Api_InterestHolder | null; interestHolders?: Api_InterestHolder[]; } export class Api_GenerateAcquisitionFile { properties: Api_GenerateH120Property[]; - property_coordinator: Api_GeneratePerson; + property_coordinator?: Api_GeneratePerson | Api_GenerateOrganization; primary_owner?: Api_GenerateOwner; owners: Api_GenerateOwner[]; person_owners: Api_GenerateOwner[]; @@ -32,9 +32,10 @@ export class Api_GenerateAcquisitionFile { file_name: string; project_number: string; project_name: string; - prov_solicitor?: Api_GeneratePerson; + prov_solicitor?: Api_GeneratePerson | Api_GenerateOrganization; + prov_solicitor_attn?: Api_GeneratePerson; owner_solicitor?: Api_GenerateInterestHolder; - neg_agent?: Api_GeneratePerson; + neg_agent?: Api_GeneratePerson | Api_GenerateOrganization; project?: Api_GenerateProject; product?: Api_GenerateProduct; @@ -47,8 +48,8 @@ export class Api_GenerateAcquisitionFile { interestHolders = [], }: IApiGenerateAcquisitionFileInput) { this.owners = file?.acquisitionFileOwners?.map(owner => new Api_GenerateOwner(owner)) ?? []; - this.property_coordinator = new Api_GeneratePerson(coordinatorContact); - this.neg_agent = new Api_GeneratePerson(negotiatingAgent); + this.property_coordinator = this.getTeam(coordinatorContact); + this.neg_agent = this.getTeam(negotiatingAgent, true); const allInterestHoldersPropertes = interestHolders.flatMap( ih => ih?.interestHolderProperties ?? [], ); @@ -84,7 +85,8 @@ export class Api_GenerateAcquisitionFile { this.primary_owner = new Api_GenerateOwner( file?.acquisitionFileOwners?.find(owner => owner.isPrimaryContact) ?? null, ); - this.prov_solicitor = new Api_GeneratePerson(provincialSolicitor); + this.prov_solicitor = this.getTeam(provincialSolicitor); + this.prov_solicitor_attn = new Api_GeneratePerson(provincialSolicitor?.primaryContact); this.owner_solicitor = new Api_GenerateInterestHolder(ownerSolicitor); this.person_owners = file?.acquisitionFileOwners @@ -99,4 +101,22 @@ export class Api_GenerateAcquisitionFile { this.all_owners_string = this.owners.map(owner => owner.owner_string).join(', '); this.all_owners_string_and = this.owners.map(owner => owner.owner_string).join(' And '); } + + getTeam = (team: Api_AcquisitionFileTeam | null, overrideOrgAddress: boolean = false) => { + if (!team) return undefined; + + if (team.person) { + return new Api_GeneratePerson(team.person); + } + + const org = new Api_GenerateOrganization(team.organization); + const primary = new Api_GeneratePerson(team.primaryContact); + //replace organization contact info with primary contact info but leave address, name. + org.phone = primary?.phone; + org.email = primary?.email; + if (overrideOrgAddress) { + org.address = primary?.address; + } + return org; + }; }