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

12656: prepopulate applicant form on landuse-form from pas-form #886

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion server/src/packages/landuse-form/landuse-form.attrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,5 +448,6 @@ export const LANDUSE_FORM_ATTRS = [
'dcp_landuse_dcp_sitedatageneralform_landuseform',
'dcp_landuse_Annotations',
'dcp_dcp_landuse_dcp_landuseaction',
'dcp_dcp_landuse_dcp_sitedatahform_landuseform'
'dcp_dcp_landuse_dcp_sitedatahform_landuseform',
'_dcp_project_value'
];
53 changes: 53 additions & 0 deletions server/src/packages/landuse-form/landuse-form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,63 @@ export class LanduseFormService {
dcp_zoningresolutionsectionactionispursuantto
`);

await this.syncApplicants(landuseForm);

landuseForm.landuseActions = landuseActionsWithZr;
return {
...landuseForm,
...landuseFormPg2,
};
}

async syncApplicants(landuseForm) {
const {
dcp_dcp_applicantinformation_dcp_landuse,
dcp_dcp_applicantrepinformation_dcp_landuse,
dcp_landuseid,
_dcp_project_value,
} = landuseForm;

const { records: [pasFormWithApplicants] } = await this.crmService.get('dcp_pasforms', `
$filter=
_dcp_projectname_value eq ${_dcp_project_value}
&$expand=
dcp_dcp_applicantinformation_dcp_pasform,
dcp_dcp_applicantrepinformation_dcp_pasform,
`);

const landuseApplicants = [...dcp_dcp_applicantinformation_dcp_landuse, ...dcp_dcp_applicantrepinformation_dcp_landuse];
const pasApplicants = [...pasFormWithApplicants.dcp_dcp_applicantinformation_dcp_pasform, ...pasFormWithApplicants.dcp_dcp_applicantrepinformation_dcp_pasform];

const landuseApplicantEmails = landuseApplicants.map(applicant => applicant.dcp_email);

await Promise.all(pasApplicants.map(pasApplicant => {
if (!landuseApplicantEmails.includes(pasApplicant.dcp_email)) {
if (pasApplicant.dcp_applicantinformationid) {

this.crmService.update(
'dcp_applicantinformations',
pasApplicant.dcp_applicantinformationid, {
'[email protected]': [
`/dcp_landuses(${dcp_landuseid})`,
],
}
);
} else if (pasApplicant.dcp_applicantrepresentativeinformationid) {

// strip the hacky prepended "representative-" to use the exact CRM id
// const representativeId = pasApplicant.dcp_applicantinformationid.replace('representative-', '');

// this.crmService.update(
// 'dcp_applicantrepresentativeinformations',
// pasApplicant.dcp_applicantinformationid, {
// '[email protected]': [
// `/dcp_landuses(${dcp_landuseid})`,
// ],
// }
// )
}
}
}));
}
}