Skip to content

Commit

Permalink
psp-6991 update agreement generation to support team organizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
devinleighsmith committed Oct 31, 2023
1 parent b857440 commit becfb1c
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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: [],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions source/frontend/src/models/generate/GenerateLetter.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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[];
Expand All @@ -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;

Expand All @@ -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 ?? [],
);
Expand Down Expand Up @@ -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
Expand All @@ -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;
};
}

0 comments on commit becfb1c

Please sign in to comment.