Skip to content

Commit

Permalink
Merge pull request #205 from bcgov/update-grazing-lease-variables
Browse files Browse the repository at this point in the history
update grazing lease variables
  • Loading branch information
mgtennant authored May 22, 2024
2 parents 34024cc + db65506 commit a0b3856
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
33 changes: 24 additions & 9 deletions backend/src/report/report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,13 @@ export class ReportService {
DB_DOCUMENT_NUMBER: dtid,
DB_DOCUMENT_TYPE: documentType.name,
DB_FILE_NUMBER: rawData ? rawData.fileNum : null,
DB_ADDRESS_STREET_TENANT: glVariables.glStreetAddress || glVariables.glMailingAddress,
DB_ADDRESS_MAILING_TENANT: glVariables.glMailingAddress || glVariables.glStreetAddress,
// DB_ADDRESS_STREET_TENANT: glVariables.glStreetAddress || glVariables.glMailingAddress,
DB_ADDRESS_STREET_TENANT: glVariables.combinedAddress,
// DB_ADDRESS_MAILING_TENANT: glVariables.glMailingAddress || glVariables.glStreetAddress,
DB_ADDRESS_MAILING_TENANT: glVariables.combinedAddress,
DB_ADDRESS_REGIONAL_OFFICE: glVariables.addressRegionalOffice,
DB_NAME_TENANT: glVariables.mailingName,
// DB_NAME_TENANT: glVariables.mailingName,
DB_NAME_TENANT: glVariables.combinedName,
DB_NAME_TENANT_LIST: glVariables.mailingNameList,
DB_NAME_CORPORATION: glVariables.mailingCorp,
DB_LEGAL_DESCRIPTION: glVariables.legalDescription,
Expand All @@ -265,14 +268,19 @@ export class ReportService {
? rawData.type.toLowerCase().charAt(0).toUpperCase() + rawData.type.toLowerCase().slice(1)
: '',
DB_REG_DOCUMENT_NUMBER: rawData ? rawData.documentNum : null,
DB_NAME_TENANTS: glVariables.combinedName,
DB_ADDRESS_TENANT: glVariables.combinedAddress,
// provide the variables in non-all caps format as well
DB_Document_Number: dtid,
DB_Document_Type: documentType.name,
DB_File_Number: rawData ? rawData.fileNum : null,
DB_Address_Street_Tenant: glVariables.glStreetAddress || glVariables.glMailingAddress,
DB_Address_Mailing_Tenant: glVariables.glMailingAddress || glVariables.glStreetAddress,
// DB_Address_Street_Tenant: glVariables.glStreetAddress || glVariables.glMailingAddress,
DB_Address_Street_Tenant: glVariables.combinedAddress,
// DB_Address_Mailing_Tenant: glVariables.glMailingAddress || glVariables.glStreetAddress,
DB_Address_Mailing_Tenant: glVariables.combinedAddress,
DB_Address_Regional_Office: glVariables.addressRegionalOffice,
DB_Name_Tenant: glVariables.mailingName,
// DB_Name_Tenant: glVariables.mailingName,
DB_Name_Tenant: glVariables.combinedName,
DB_Name_Tenant_List: glVariables.mailingNameList,
DB_Name_Corporation: glVariables.mailingCorp,
DB_Legal_Description: glVariables.legalDescription,
Expand All @@ -282,6 +290,8 @@ export class ReportService {
? rawData.type.toLowerCase().charAt(0).toUpperCase() + rawData.type.slice(1).toLowerCase()
: '',
DB_Reg_Document_Number: rawData ? rawData.documentNum : null,
DB_Name_Tenants: glVariables.combinedName,
DB_Address_Tenant: glVariables.combinedAddress,
};
}

Expand Down Expand Up @@ -469,13 +479,18 @@ export class ReportService {
const data = {
DB_File_Number: rawData.fileNum,
DB_Document_Number: dtid,
DB_Address_Street_Tenant: glVariables.glStreetAddress || glVariables.glMailingAddress,
// DB_Address_Street_Tenant: glVariables.glStreetAddress || glVariables.glMailingAddress,
DB_Address_Street_Tenant: glVariables.combinedAddress,
DB_Address_Regional_Office: glVariables.addressRegionalOffice,
DB_Address_Mailing_Tenant: glVariables.glMailingAddress || glVariables.glStreetAddress,
DB_Name_Tenant: glVariables.mailingName,
// DB_Address_Mailing_Tenant: glVariables.glMailingAddress || glVariables.glStreetAddress,
DB_Address_Mailing_Tenant: glVariables.combinedAddress,
// DB_Name_Tenant: glVariables.mailingName,
DB_Name_Tenant: glVariables.combinedName,
DB_Name_Tenant_List: glVariables.mailingNameList,
DB_Name_Corporation: glVariables.mailingCorp,
DB_Legal_Description: glVariables.legalDescription,
DB_Name_Tenants: glVariables.combinedName,
DB_Address_Tenant: glVariables.combinedAddress,
};

// log the request
Expand Down
26 changes: 23 additions & 3 deletions backend/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,16 @@ export function glAddressBuilder(
provAbbr: string;
postalCode: string;
}[]
): { glMailingAddress: string; glStreetAddress: string } {
): { glMailingAddress: string; glStreetAddress: string; combinedAddress: string } {
if (!tenantAddr) {
return { glMailingAddress: '', glStreetAddress: '' };
return { glMailingAddress: '', glStreetAddress: '', combinedAddress: '' };
}
const uniqueMailingAddresses = new Map<
string,
{ names: Set<string>; addressLines: string; cityProvPostal: string }
>();
const uniqueStreetAddresses = new Map<string, { names: Set<string>; addressLines: string; cityProvPostal: string }>();
const uniqueAddresses = new Map<string, { names: Set<string>; addressLines: string; cityProvPostal: string }>();

for (const addressObj of tenantAddr) {
const {
Expand Down Expand Up @@ -193,6 +194,12 @@ export function glAddressBuilder(
uniqueStreetAddresses.set(key, { names: new Set([name]), addressLines: joinedAddressLines, cityProvPostal });
}
}
if (uniqueAddresses.has(key)) {
const existingEntry = uniqueAddresses.get(key);
existingEntry.names.add(name);
} else {
uniqueAddresses.set(key, { names: new Set([name]), addressLines: joinedAddressLines, cityProvPostal });
}
}

const formattedMailingAddresses: string[] = [];
Expand All @@ -207,9 +214,16 @@ export function glAddressBuilder(
formattedStreetAddresses.push(`${formattedNames}\n${addressLines}\n${cityProvPostal}\n`);
}

const formattedAddresses: string[] = [];
for (const { names, addressLines, cityProvPostal } of uniqueAddresses.values()) {
const formattedNames = Array.from(names).join('\n');
formattedAddresses.push(`${formattedNames}\n${addressLines}\n${cityProvPostal}\n`);
}

return {
glMailingAddress: formattedMailingAddresses.join('\n'),
glStreetAddress: formattedStreetAddresses.join('\n'),
combinedAddress: formattedAddresses.join('\n'),
};
}

Expand All @@ -225,6 +239,8 @@ export function grazingLeaseVariables(
mailingName: string;
mailingNameList: { name: string }[];
mailingCorp: string;
combinedAddress: string;
combinedName: string;
legalDescription: string;
addressRegionalOffice: string;
glMailingAddress: string;
Expand All @@ -238,9 +254,10 @@ export function grazingLeaseVariables(
let mailingName = '';
let mailingNameList = [];
let mailingCorp = '';
let combinedName = '';
let legalDescription = '';
let addressRegionalOffice = '';
const { glMailingAddress, glStreetAddress } = glAddressBuilder(tenantAddr);
const { glMailingAddress, glStreetAddress, combinedAddress } = glAddressBuilder(tenantAddr);

if (tenantAddr) {
for (let tenant of tenantAddr) {
Expand All @@ -262,6 +279,7 @@ export function grazingLeaseVariables(
const tempStreetCorp = getCorp(tenant);
streetCorp = streetCorp.length > 0 ? [streetCorp, tempStreetCorp].join('\n ') : tempStreetCorp;
}
combinedName = combinedName.length > 0 ? [combinedName, getFullName(tenant)].join('\n ') : getFullName(tenant);
}

// if either address is empty, set it to the other
Expand Down Expand Up @@ -322,6 +340,8 @@ export function grazingLeaseVariables(
addressRegionalOffice,
glMailingAddress,
glStreetAddress,
combinedAddress,
combinedName,
};
}

Expand Down

0 comments on commit a0b3856

Please sign in to comment.