From e28895e0d33804f9a953fca39087f39b107e6d6a Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Wed, 25 Oct 2023 16:28:15 -0700 Subject: [PATCH 1/5] WIP --- backend/src/main.ts | 2 +- .../entities/grazing_lease_vw.ts | 63 ++++ .../dto/create-print_request_log.dto.ts | 1 + .../dto/print_request_log.dto.ts | 1 + .../dto/update-print_request_log.dto.ts | 1 + .../entities/print_request_log.entity.ts | 4 + .../print_request_log.service.ts | 1 + frontend/public/js/manage-templates.js | 59 ++-- frontend/public/js/nfr.js | 1 + frontend/src/app.controller.ts | 316 +++++++++++------- .../authentication/authentication.filter.ts | 1 + .../authentication/http-exception.filter.ts | 1 - frontend/src/report/report.service.ts | 1 + frontend/utils/constants.ts | 7 +- frontend/views/pages/grazing-lease.hbs | 154 +++++++++ 15 files changed, 475 insertions(+), 138 deletions(-) create mode 100644 backend/src/print_request_detail/entities/grazing_lease_vw.ts create mode 100644 frontend/views/pages/grazing-lease.hbs diff --git a/backend/src/main.ts b/backend/src/main.ts index 26828abf..40d2a192 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -16,6 +16,6 @@ async function bootstrap() { SwaggerModule.setup("api", app, document); const appService = app.get(AppService); // await appService.initializeDb(); - await app.listen(3000); + await app.listen(3001); } bootstrap(); diff --git a/backend/src/print_request_detail/entities/grazing_lease_vw.ts b/backend/src/print_request_detail/entities/grazing_lease_vw.ts new file mode 100644 index 00000000..a9161116 --- /dev/null +++ b/backend/src/print_request_detail/entities/grazing_lease_vw.ts @@ -0,0 +1,63 @@ +import { DataSource, ViewColumn, ViewEntity } from "typeorm"; +import { PrintRequestDetail } from "./print_request_detail.entity"; + +@ViewEntity({ + expression: (dataSource: DataSource) => + dataSource + .createQueryBuilder() + .select("print_request_detail.dtid", "DB_Document_Number") + .addSelect("print_request_detail.tenure_file_number", "DB_File_Number") + .addSelect("print_request_detail.organization_unit", "OrganizationUnit") + .addSelect("print_request_detail.purpose_name", "Purpose") + .addSelect("print_request_detail.sub_purpose_name", "SubPurpose") + .addSelect("print_request_detail.type_name", "TenureType") + .addSelect("print_request_detail.sub_type_name", "TenureSubType") + .addSelect( + "print_request_detail.licence_holder_name", + "LicenceHolderName" + ) + .addSelect("print_request_detail.mailing_address", "MailingAddress") + .addSelect("print_request_detail.mailing_city", "MailingCity") + .addSelect( + "print_request_detail.mailing_province_state_code", + "MailingProv" + ) + .addSelect("print_request_detail.mailing_postal_code", "PostCode") + .addSelect("print_request_detail.email_address", "PrimaryContactEmail") + .addSelect("print_request_detail.phone_number", "PrimaryContactPhone") + .addSelect("print_request_detail.location_description", "Location") + .addSelect("print_request_detail.tenure", "Tenure") + .addSelect("print_request_detail.contact_agent", "ContactAgent") + .addSelect( + "print_request_detail.contact_email_address", + "ContactAgentEmail" + ) + .addSelect( + "print_request_detail.contact_phone_number", + "ContactAgentPhone" + ) + .addSelect("print_request_detail.inspected_date", "InspectionDate") + .addSelect( + "print_request_detail.incorporation_number", + "IncorporationNumber" + ) + .from(PrintRequestDetail, "print_request_detail"), +}) +export class GrazingLeaseView { + @ViewColumn() + DB_Document_Number: number; + @ViewColumn() + DB_File_Number: string; + @ViewColumn() + DB_Address_Street_Tenant: string; + @ViewColumn() + DB_Address_Regional_Office: string; + @ViewColumn() + DB_Address_Mailing_Tenant: string; + @ViewColumn() + DB_Name_Tenant: string; + @ViewColumn() + DB_Name_Corporation: string; + @ViewColumn() + DB_Legal_Description: string; +} diff --git a/backend/src/print_request_log/dto/create-print_request_log.dto.ts b/backend/src/print_request_log/dto/create-print_request_log.dto.ts index a825d7a5..e725d0fe 100644 --- a/backend/src/print_request_log/dto/create-print_request_log.dto.ts +++ b/backend/src/print_request_log/dto/create-print_request_log.dto.ts @@ -5,6 +5,7 @@ export class CreatePrintRequestLogDto extends PickType(PrintRequestLogDto, [ "document_template_id", "print_request_detail_id", "dtid", + "document_type", "request_app_user", "request_json", "create_userid", diff --git a/backend/src/print_request_log/dto/print_request_log.dto.ts b/backend/src/print_request_log/dto/print_request_log.dto.ts index 3af901cd..a9f34bdc 100644 --- a/backend/src/print_request_log/dto/print_request_log.dto.ts +++ b/backend/src/print_request_log/dto/print_request_log.dto.ts @@ -2,6 +2,7 @@ export class PrintRequestLogDto { document_template_id: number; print_request_detail_id: number; dtid: number; + document_type: string; request_app_user: string; request_json: string; create_userid: string; diff --git a/backend/src/print_request_log/dto/update-print_request_log.dto.ts b/backend/src/print_request_log/dto/update-print_request_log.dto.ts index 3aaf8f30..cfe281cc 100644 --- a/backend/src/print_request_log/dto/update-print_request_log.dto.ts +++ b/backend/src/print_request_log/dto/update-print_request_log.dto.ts @@ -5,6 +5,7 @@ export class UpdatePrintRequestLogDto extends PickType(PrintRequestLogDto, [ "document_template_id", "print_request_detail_id", "dtid", + "document_type", "request_app_user", "request_json", "update_userid", diff --git a/backend/src/print_request_log/entities/print_request_log.entity.ts b/backend/src/print_request_log/entities/print_request_log.entity.ts index 33c3c979..9143324a 100644 --- a/backend/src/print_request_log/entities/print_request_log.entity.ts +++ b/backend/src/print_request_log/entities/print_request_log.entity.ts @@ -16,6 +16,8 @@ export class PrintRequestLog { print_request_detail_id: number; @Column({ nullable: true }) dtid: number; + @Column({nullable: true}) + document_type: string; @Column({ nullable: true }) request_app_user: string; @Column({ nullable: true }) @@ -33,6 +35,7 @@ export class PrintRequestLog { document_template_id?: number, print_request_detail_id?: number, dtid?: number, + document_type?: string, request_app_user?: string, request_json?: string, create_userid?: string, @@ -41,6 +44,7 @@ export class PrintRequestLog { this.document_template_id = document_template_id || null; this.print_request_detail_id = print_request_detail_id || null; this.dtid = dtid || null; + this.document_type = document_type || ""; this.request_app_user = request_app_user || ""; this.request_json = request_json || ""; this.create_userid = create_userid || ""; diff --git a/backend/src/print_request_log/print_request_log.service.ts b/backend/src/print_request_log/print_request_log.service.ts index 03e4f2ef..95f45d1e 100644 --- a/backend/src/print_request_log/print_request_log.service.ts +++ b/backend/src/print_request_log/print_request_log.service.ts @@ -18,6 +18,7 @@ export class PrintRequestLogService { newItem.document_template_id = printRequestLog.document_template_id; newItem.print_request_detail_id = printRequestLog.print_request_detail_id; newItem.dtid = printRequestLog.dtid; + newItem.document_type = printRequestLog.document_type; newItem.request_app_user = printRequestLog.request_app_user; newItem.request_json = printRequestLog.request_json; newItem.create_userid = printRequestLog.request_app_user; // same as request_app_user diff --git a/frontend/public/js/manage-templates.js b/frontend/public/js/manage-templates.js index 6f56912f..1a181bfd 100644 --- a/frontend/public/js/manage-templates.js +++ b/frontend/public/js/manage-templates.js @@ -1,6 +1,8 @@ -var documentTable, groupMaxTable, provisionTable, editProvisionVariableTable; -var documentTable2, documentTable3, documentTable4, documentTable5; +var documentTable; // main template upload table +var groupMaxTable, provisionTable, editProvisionVariableTable; +var documentTable2, documentTable3, documentTable4, documentTable5; // nfr variants var reportType = ""; +var reportTitle = ""; var nfrDelayed = "NOTICE OF FINAL REVIEW (DELAYED)"; var nfrNoFees = "NOTICE OF FINAL REVIEW (NO FEES)"; var nfrSurveyReq = "NOTICE OF FINAL REVIEW (SURVEY REQUIRED)"; @@ -11,19 +13,23 @@ $(document).ready(function () { if (reportIndex != 2) { $(".nofr-section").hide(); } - reportType = - reportIndex == 1 - ? "LAND USE REPORT" - : reportIndex == 2 - ? "NOTICE OF FINAL REVIEW" - : ""; - $("#reportTitle").text( - reportIndex == 1 - ? "Land Use Report" - : reportIndex == 2 - ? "Notice of Final Review" - : "" - ); + switch (reportIndex) { + case 1: + reportType = "LAND USE REPORT"; + reportTitle = "Land Use Report"; + break; + case 2: + reportType = "NOTICE OF FINAL REVIEW"; + reportTitle = "Notice of Final Review"; + break; + case 3: + reportType = "GRAZING LEASE"; + reportTitle = "Grazing Lease"; + break; + default: + break; + } + $("#reportTitle").text(reportTitle); // used for sorting the radio buttons $.fn.dataTable.ext.order["dom-checkbox"] = function (settings, col) { return this.api() @@ -98,6 +104,7 @@ $(document).ready(function () { }, order: [[0, "asc"]], }); + // nfr section if (reportIndex == 2) { documentTable2 = $("#documentTable2").DataTable({ ajax: { @@ -577,12 +584,20 @@ function removeTemplate() { const id = $("#document-template-id").val(); const urlParams = new URLSearchParams(window.location.search); const reportIndex = parseInt(urlParams.get("report")); - const reportType = - reportIndex == 1 - ? "LAND USE REPORT" - : reportIndex == 2 - ? "NOTICE OF FINAL REVIEW" - : ""; + let reportType = ""; + switch (reportIndex) { + case 1: + reportType = "LAND USE REPORT"; + break; + case 2: + reportType = "NOTICE OF FINAL REVIEW"; + break; + case 3: + reportType = "GRAZING LEASE"; + break; + default: + break; + } fetch(`/admin/remove-template/${reportType}/${id}`, { method: "GET", }) @@ -921,7 +936,7 @@ function openEditModal() { const provision_group = $(`#provision_group-${provisionId}`).val(); const max = $(`#max-${provisionId}`).val(); const provision_name = $(`#provision_name-${provisionId}`).val(); - const free_text = $(`#free_text-${provisionId}`).data('fullval') + const free_text = $(`#free_text-${provisionId}`).data("fullval"); const help_text = $(`#help_text-${provisionId}`).val(); const category = $(`#category-${provisionId}`).val(); const variants = $(this).data("variants"); diff --git a/frontend/public/js/nfr.js b/frontend/public/js/nfr.js index 0ff4862b..379983ac 100644 --- a/frontend/public/js/nfr.js +++ b/frontend/public/js/nfr.js @@ -33,6 +33,7 @@ $(".legalDesc").each(function () { }); if ($("#adminLink").text() == "-") { $("#adminLink").hide(); + $("#adminLink").text(""); } groupMaxTable = $("#groupMaxTable").DataTable({ ajax: { diff --git a/frontend/src/app.controller.ts b/frontend/src/app.controller.ts index 0ac8a25f..d79013c6 100644 --- a/frontend/src/app.controller.ts +++ b/frontend/src/app.controller.ts @@ -10,7 +10,6 @@ import { Res, } from "@nestjs/common"; import { AppService } from "./app.service"; -import { AdminService } from "./admin/admin.service"; import { NFR_VARIANTS, NFR_VARIANTS_ARRAY, @@ -24,7 +23,6 @@ import { TTLSService } from "./ttls/ttls.service"; import { AdminGuard } from "./admin/admin.guard"; import { AxiosRequestConfig } from "axios"; import { firstValueFrom } from "rxjs"; -import { HttpService } from "@nestjs/axios"; import { Req } from "@nestjs/common/decorators/http/route-params.decorator"; import { Request, Response } from "express"; import { ReportService } from "./report/report.service"; @@ -89,7 +87,6 @@ export class AppController { * * @param session * @param id - * @param docname * @returns */ @Get("dtid/:id") @@ -102,6 +99,7 @@ export class AppController { @Req() request: Request, @Res() response: Response ) { + console.log("LUR"); const hasParams = request.originalUrl.includes("?session_state"); if (hasParams) { const urlWithoutParams = request.path; @@ -156,7 +154,11 @@ export class AppController { primaryContactName: primaryContactName, displayAdmin: displayAdmin, message: ttlsJSON, - documentTypes: ["Land Use Report", "Notice of Final Review"], + documentTypes: [ + "Land Use Report", + "Notice of Final Review", + "Grazing Lease", + ], prdid: ttlsJSON.id, }; } catch (err) { @@ -169,7 +171,11 @@ export class AppController { primaryContactName: primaryContactName ? primaryContactName : null, displayAdmin: displayAdmin, message: ttlsJSON ? ttlsJSON : null, - documentTypes: ["Land Use Report", "Notice of Final Review"], + documentTypes: [ + "Land Use Report", + "Notice of Final Review", + "Grazing Lease", + ], prdid: ttlsJSON ? ttlsJSON.id : null, error: err, }; @@ -178,132 +184,42 @@ export class AppController { } /** - * Renders the NFR report page + * Renders the survey required NFR report page * * @param session - * @param id - * @param docname + * @param dtid * @returns */ - @Get("dtid/:dtid/:variant") + @Get("dtid/:dtid/:documentType") @UseFilters(AuthenticationFilter) @UseGuards(AuthenticationGuard) - @Render("nfr") - async findNofr( + async reportPage( @Session() session: { data?: SessionData }, @Param("dtid") dtid: number, - @Param("variant") variantName: string, + @Param("documentType") documentType: string, @Req() req: Request, @Res() res: Response ) { + const decodedDocumentType = decodeURIComponent(documentType).toUpperCase(); + console.log(decodedDocumentType); + console.log("888"); + console.log(documentType); + console.log("888"); const hasParams = req.originalUrl.includes("?session_state"); if (hasParams) { const urlWithoutParams = req.path; res.redirect(301, urlWithoutParams); - } else if (!NFR_VARIANTS_ARRAY.includes(variantName)) { + } else if ( + !NFR_VARIANTS_ARRAY.includes(decodedDocumentType) && + decodedDocumentType != "GRAZINGLEASE" + ) { const redirectUrl = `/dtid/${dtid}`; res.redirect(301, redirectUrl); } else { - let isAdmin = false; - if ( - session.data && - session.data.activeAccount && - session.data.activeAccount.client_roles - ) { - for (let role of session.data.activeAccount.client_roles) { - if (role == "ticdi_admin") { - isAdmin = true; - } - } - } - const title = - process.env.ticdi_environment == "DEVELOPMENT" - ? "DEVELOPMENT - " + PAGE_TITLES.NOFR - : PAGE_TITLES.NOFR; - const displayAdmin = isAdmin ? "Administration" : "-"; - const groupMaxJsonArray = await this.reportService.getGroupMaxByVariant( - variantName - ); - let ttlsJSON, primaryContactName, nfrData; - try { - const nfrDataObject = await this.reportService.getActiveNfrDataByDtid( - dtid - ); - nfrData = nfrDataObject.nfrData; - const provisionIds = nfrDataObject.provisionIds - ? nfrDataObject.provisionIds - : []; - const mandatoryProvisionIds = - await this.reportService.getMandatoryProvisionsByVariant(variantName); - await this.ttlsService.setWebadeToken(); - const response: any = await firstValueFrom( - this.ttlsService.callHttp(dtid) - ) - .then((res) => { - return res; - }) - .catch((err) => { - console.log(err.response.data); - }); - ttlsJSON = await this.ttlsService.formatNFRData(response); - primaryContactName = ttlsJSON.licenceHolderName; - const interestedParties = nfrInterestedParties(response.tenantAddr); - ttlsJSON["interestedParties"] = interestedParties; - let selectedVariant = 0; - switch (variantName.toLowerCase()) { - case NFR_VARIANTS.default.toLowerCase(): { - selectedVariant = 0; - break; - } - case NFR_VARIANTS.delayed.toLowerCase(): { - selectedVariant = 1; - break; - } - case NFR_VARIANTS.no_fees.toLowerCase(): { - selectedVariant = 2; - break; - } - case NFR_VARIANTS.survey_required.toLowerCase(): { - selectedVariant = 3; - break; - } - case NFR_VARIANTS.to_obtain_survey.toLowerCase(): { - selectedVariant = 4; - break; - } - } - return { - title: title, - idirUsername: session.data.activeAccount - ? session.data.activeAccount.idir_username - : "", - primaryContactName: primaryContactName, - displayAdmin: displayAdmin, - message: ttlsJSON, - groupMaxJsonArray: groupMaxJsonArray, - documentTypes: NFR_VARIANTS_ARRAY, - nfrDataId: nfrData ? nfrData.id : -1, - selectedVariant: selectedVariant, - mandatoryProvisionList: mandatoryProvisionIds, - // enabledProvisionList: enabledProvisions, - enabledProvisionList: provisionIds, - }; - } catch (err) { - console.log(err); - return { - title: title, - idirUsername: session.data.activeAccount - ? session.data.activeAccount.idir_username - : "", - primaryContactName: primaryContactName ? primaryContactName : null, - displayAdmin: displayAdmin, - message: ttlsJSON ? ttlsJSON : null, - groupMaxJsonArray: groupMaxJsonArray, - documentTypes: NFR_VARIANTS_ARRAY, - nfrDataId: -1, - enabledProvisionList: [], - error: err, - }; + if (decodedDocumentType == "GRAZINGLEASE") { + return this.getGrazingLeaseDisplayData(session, dtid, res); + } else { + return this.getNfrDisplayData(session, dtid, documentType, res); } } } @@ -340,6 +256,7 @@ export class AppController { reportTypes: [ { reportType: REPORT_TYPES[0], reportIndex: 1 }, { reportType: REPORT_TYPES[1], reportIndex: 2 }, + { reportType: REPORT_TYPES[2], reportIndex: 3 }, ], }; } @@ -459,4 +376,177 @@ export class AppController { displayAdmin: displayAdmin, }; } + + // grabs Grazing Lease display data and displays the grazing lease report page + async getGrazingLeaseDisplayData(session, dtid, res) { + let isAdmin = false; + if ( + session.data && + session.data.activeAccount && + session.data.activeAccount.client_roles + ) { + for (let role of session.data.activeAccount.client_roles) { + if (role == "ticdi_admin") { + isAdmin = true; + } + } + } + const title = + process.env.ticdi_environment == "DEVELOPMENT" + ? "DEVELOPMENT - " + PAGE_TITLES.GRAZING_LEASE + : PAGE_TITLES.GRAZING_LEASE; + const displayAdmin = isAdmin ? "Administration" : "-"; + await this.ttlsService.setWebadeToken(); + let ttlsJSON, primaryContactName; + try { + const response: any = await firstValueFrom( + this.ttlsService.callHttp(dtid) + ) + .then((res) => { + return res; + }) + .catch((err) => { + console.log("callHttp failed"); + console.log(err); + console.log(err.response.data); + }); + ttlsJSON = await this.ttlsService.sendToBackend(response); + ttlsJSON["cityProvPostal"] = this.ttlsService.concatCityProvPostal( + response.tenantAddr ? response.tenantAddr[0] : null + ); + if (ttlsJSON.inspected_date) { + ttlsJSON["inspected_date"] = this.ttlsService.formatInspectedDate( + ttlsJSON.inspected_date.toString() + ); + } + primaryContactName = ttlsJSON.licence_holder_name; + return res.render("grazing-lease", { + title: title, + idirUsername: session.data.activeAccount + ? session.data.activeAccount.idir_username + : "", + primaryContactName: primaryContactName, + displayAdmin: displayAdmin, + message: ttlsJSON, + prdid: ttlsJSON.id, + }); + } catch (err) { + console.log(err); + return res.render("grazing-lease", { + title: title, + idirUsername: session.data.activeAccount + ? session.data.activeAccount.idir_username + : "", + primaryContactName: primaryContactName ? primaryContactName : null, + displayAdmin: displayAdmin, + message: ttlsJSON ? ttlsJSON : null, + prdid: ttlsJSON ? ttlsJSON.id : null, + error: err, + }); + } + } + + // grabs NFR data and displays the correct NFR page + async getNfrDisplayData(session, dtid, variantName, res) { + let ttlsJSON, primaryContactName, nfrData; + let isAdmin = false; + if ( + session.data && + session.data.activeAccount && + session.data.activeAccount.client_roles + ) { + for (let role of session.data.activeAccount.client_roles) { + if (role == "ticdi_admin") { + isAdmin = true; + } + } + } + const title = + process.env.ticdi_environment == "DEVELOPMENT" + ? "DEVELOPMENT - " + PAGE_TITLES.NOFR + : PAGE_TITLES.NOFR; + const displayAdmin = isAdmin ? "Administration" : "-"; + const groupMaxJsonArray = await this.reportService.getGroupMaxByVariant( + "NOTICE OF FINAL REVIEW" + ); + try { + const nfrDataObject = await this.reportService.getActiveNfrDataByDtid( + dtid + ); + nfrData = nfrDataObject.nfrData; + const provisionIds = nfrDataObject.provisionIds + ? nfrDataObject.provisionIds + : []; + const mandatoryProvisionIds = + await this.reportService.getMandatoryProvisionsByVariant(variantName); + await this.ttlsService.setWebadeToken(); + const response: any = await firstValueFrom( + this.ttlsService.callHttp(dtid) + ) + .then((res) => { + return res; + }) + .catch((err) => { + console.log(err.response.data); + }); + ttlsJSON = await this.ttlsService.formatNFRData(response); + primaryContactName = ttlsJSON.licenceHolderName; + const interestedParties = nfrInterestedParties(response.tenantAddr); + ttlsJSON["interestedParties"] = interestedParties; + let selectedVariant = 0; + switch (variantName.toLowerCase()) { + case NFR_VARIANTS.default.toLowerCase(): { + selectedVariant = 0; + break; + } + case NFR_VARIANTS.delayed.toLowerCase(): { + selectedVariant = 1; + break; + } + case NFR_VARIANTS.no_fees.toLowerCase(): { + selectedVariant = 2; + break; + } + case NFR_VARIANTS.survey_required.toLowerCase(): { + selectedVariant = 3; + break; + } + case NFR_VARIANTS.to_obtain_survey.toLowerCase(): { + selectedVariant = 4; + break; + } + } + return res.render("nfr", { + title: title, + idirUsername: session.data.activeAccount + ? session.data.activeAccount.idir_username + : "", + primaryContactName: primaryContactName, + displayAdmin: displayAdmin, + message: ttlsJSON, + groupMaxJsonArray: groupMaxJsonArray, + documentTypes: NFR_VARIANTS_ARRAY, + nfrDataId: nfrData ? nfrData.id : -1, + selectedVariant: selectedVariant, + mandatoryProvisionList: mandatoryProvisionIds, + enabledProvisionList: provisionIds, + }); + } catch (err) { + console.log(err); + return res.render("nfr", { + title: title, + idirUsername: session.data.activeAccount + ? session.data.activeAccount.idir_username + : "", + primaryContactName: primaryContactName ? primaryContactName : null, + displayAdmin: displayAdmin, + message: ttlsJSON ? ttlsJSON : null, + groupMaxJsonArray: groupMaxJsonArray, + documentTypes: NFR_VARIANTS_ARRAY, + nfrDataId: -1, + enabledProvisionList: [], + error: err, + }); + } + } } diff --git a/frontend/src/authentication/authentication.filter.ts b/frontend/src/authentication/authentication.filter.ts index 18ff42af..c09f4601 100644 --- a/frontend/src/authentication/authentication.filter.ts +++ b/frontend/src/authentication/authentication.filter.ts @@ -18,6 +18,7 @@ export class AuthenticationFilter implements ExceptionFilter { keycloak_login_baseurl + "?" + keycloak_login_params; } catch(exception: any, host: ArgumentsHost) { + console.log(exception); if (exception.status == HttpStatus.UNAUTHORIZED) { console.log("unauth"); const ctx = host.switchToHttp(); diff --git a/frontend/src/authentication/http-exception.filter.ts b/frontend/src/authentication/http-exception.filter.ts index c26fc178..feee263f 100644 --- a/frontend/src/authentication/http-exception.filter.ts +++ b/frontend/src/authentication/http-exception.filter.ts @@ -1,5 +1,4 @@ import { ExceptionFilter, Catch, NotFoundException } from "@nestjs/common"; -import { Request, Response } from "express"; @Catch(NotFoundException) export class HttpExceptionFilter implements ExceptionFilter { diff --git a/frontend/src/report/report.service.ts b/frontend/src/report/report.service.ts index 64d21193..b0b4701a 100644 --- a/frontend/src/report/report.service.ts +++ b/frontend/src/report/report.service.ts @@ -100,6 +100,7 @@ export class ReportService { await axios.post(logUrl, { document_template_id: document_template_id, print_request_detail_id: prdid, + document_type: documentType, dtid: data.DTID, request_app_user: username, request_json: JSON.stringify(data), diff --git a/frontend/utils/constants.ts b/frontend/utils/constants.ts index 3b0023b0..9f44e752 100644 --- a/frontend/utils/constants.ts +++ b/frontend/utils/constants.ts @@ -1,6 +1,7 @@ export const PAGE_TITLES = { INDEX: "TICDI", NOFR: "Notice of Final Review", + GRAZING_LEASE: "Grazing Lease", ADMIN: "System Administration", MANAGE_TEMPLATES: "Manage Templates", MANAGE_USERS: "Manage Users", @@ -10,7 +11,11 @@ export const PAGE_TITLES = { export const LUR_REPORT_TYPE = "LAND USE REPORT"; // Used for admin page dropdown for manage templates page -export const REPORT_TYPES = ["Land Use Report", "Notice of Final Review"]; +export const REPORT_TYPES = [ + "Land Use Report", + "Notice of Final Review", + "Grazing Lease", +]; export const NFR_VARIANTS_ARRAY = [ "NOTICE OF FINAL REVIEW", diff --git a/frontend/views/pages/grazing-lease.hbs b/frontend/views/pages/grazing-lease.hbs new file mode 100644 index 00000000..8c2115ed --- /dev/null +++ b/frontend/views/pages/grazing-lease.hbs @@ -0,0 +1,154 @@ +{{#> template}} + {{#*inline "content"}} + + + + Preview - Grazing Lease + + + DTID: {{message.dtid}} + Tenure File Number: {{message.tenure_file_number}} + Primary Contact Name: {{primaryContactName}} + + + Disposition Transaction ID Details + + + + Contact/Agent Name + {{message.contact_agent}} + + + Organization Unit + {{ message.organization_unit }} + + + + + + Primary Contact Email Address + {{ message.email_address }} + + + Primary Contact Phone Number + {{ message.phone_number }} + + + + + Contact/Agent Email Address + {{ message.contact_email_address }} + + + Contact/Agent Phone Number + {{ message.contact_phone_number }} + + + + + Incorporation Number + {{ message.incorporation_number }} + + + Inspected Date + {{ message.inspected_date }} + + + + + + Tenure Details + + + + Type + {{ message.type_name }} + + + Subtype + {{message.sub_type_name}} + + + + + Purpose + {{ message.purpose_name }} + + + Subpurpose + {{message.sub_purpose_name}} + + + + + Mailing Address + {{message.mailing_address}} + {{message.cityProvPostal}} + {{message.mailing_country}} + + + Location of Land + {{message.location_description}} + + + + + + Area + + {{#each message.tenure}} + + + Area + {{ this.Area }} + + + Legal Description + {{this.LegalDescription}} + + + {{/each}} + + + + + Create + + + + + + + + {{/inline}} +{{/template}} \ No newline at end of file From 9680e1fa98eae9e9c683d5e848e214b87c9fbbfa Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Thu, 26 Oct 2023 09:09:05 -0700 Subject: [PATCH 2/5] revert dev port change --- backend/src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main.ts b/backend/src/main.ts index 40d2a192..26828abf 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -16,6 +16,6 @@ async function bootstrap() { SwaggerModule.setup("api", app, document); const appService = app.get(AppService); // await appService.initializeDb(); - await app.listen(3001); + await app.listen(3000); } bootstrap(); From 06b40e2079aede18dbb5d947c0b20bcf5f490c70 Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Thu, 26 Oct 2023 12:25:57 -0700 Subject: [PATCH 3/5] generates doc but variables are off --- .../entities/grazing_lease_vw.ts | 63 ---------- .../print_request_log.controller.ts | 6 +- .../print_request_log.service.ts | 15 ++- frontend/public/js/util.js | 11 +- frontend/src/app.controller.ts | 12 +- .../authentication/authentication.filter.ts | 1 - frontend/src/report/report.controller.ts | 26 ++-- frontend/src/report/report.service.ts | 118 ++++++++++++++++-- frontend/utils/constants.ts | 9 ++ frontend/views/pages/grazing-lease.hbs | 2 +- frontend/views/pages/index.hbs | 2 +- 11 files changed, 161 insertions(+), 104 deletions(-) delete mode 100644 backend/src/print_request_detail/entities/grazing_lease_vw.ts diff --git a/backend/src/print_request_detail/entities/grazing_lease_vw.ts b/backend/src/print_request_detail/entities/grazing_lease_vw.ts deleted file mode 100644 index a9161116..00000000 --- a/backend/src/print_request_detail/entities/grazing_lease_vw.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { DataSource, ViewColumn, ViewEntity } from "typeorm"; -import { PrintRequestDetail } from "./print_request_detail.entity"; - -@ViewEntity({ - expression: (dataSource: DataSource) => - dataSource - .createQueryBuilder() - .select("print_request_detail.dtid", "DB_Document_Number") - .addSelect("print_request_detail.tenure_file_number", "DB_File_Number") - .addSelect("print_request_detail.organization_unit", "OrganizationUnit") - .addSelect("print_request_detail.purpose_name", "Purpose") - .addSelect("print_request_detail.sub_purpose_name", "SubPurpose") - .addSelect("print_request_detail.type_name", "TenureType") - .addSelect("print_request_detail.sub_type_name", "TenureSubType") - .addSelect( - "print_request_detail.licence_holder_name", - "LicenceHolderName" - ) - .addSelect("print_request_detail.mailing_address", "MailingAddress") - .addSelect("print_request_detail.mailing_city", "MailingCity") - .addSelect( - "print_request_detail.mailing_province_state_code", - "MailingProv" - ) - .addSelect("print_request_detail.mailing_postal_code", "PostCode") - .addSelect("print_request_detail.email_address", "PrimaryContactEmail") - .addSelect("print_request_detail.phone_number", "PrimaryContactPhone") - .addSelect("print_request_detail.location_description", "Location") - .addSelect("print_request_detail.tenure", "Tenure") - .addSelect("print_request_detail.contact_agent", "ContactAgent") - .addSelect( - "print_request_detail.contact_email_address", - "ContactAgentEmail" - ) - .addSelect( - "print_request_detail.contact_phone_number", - "ContactAgentPhone" - ) - .addSelect("print_request_detail.inspected_date", "InspectionDate") - .addSelect( - "print_request_detail.incorporation_number", - "IncorporationNumber" - ) - .from(PrintRequestDetail, "print_request_detail"), -}) -export class GrazingLeaseView { - @ViewColumn() - DB_Document_Number: number; - @ViewColumn() - DB_File_Number: string; - @ViewColumn() - DB_Address_Street_Tenant: string; - @ViewColumn() - DB_Address_Regional_Office: string; - @ViewColumn() - DB_Address_Mailing_Tenant: string; - @ViewColumn() - DB_Name_Tenant: string; - @ViewColumn() - DB_Name_Corporation: string; - @ViewColumn() - DB_Legal_Description: string; -} diff --git a/backend/src/print_request_log/print_request_log.controller.ts b/backend/src/print_request_log/print_request_log.controller.ts index 935cd868..1dda5df3 100644 --- a/backend/src/print_request_log/print_request_log.controller.ts +++ b/backend/src/print_request_log/print_request_log.controller.ts @@ -27,8 +27,8 @@ export class PrintRequestLogController { return this.printRequestLogService.findByDtid(+dtid); } - @Get("version/:dtid") - findNextVersion(@Param("dtid") dtid: string): Promise { - return this.printRequestLogService.findNextVersion(+dtid); + @Get("version/:dtid/:documentType") + findNextVersion(@Param("dtid") dtid: string, @Param("documentType") documentType: string): Promise { + return this.printRequestLogService.findNextVersion(+dtid, documentType); } } diff --git a/backend/src/print_request_log/print_request_log.service.ts b/backend/src/print_request_log/print_request_log.service.ts index 95f45d1e..444b730e 100644 --- a/backend/src/print_request_log/print_request_log.service.ts +++ b/backend/src/print_request_log/print_request_log.service.ts @@ -38,10 +38,23 @@ export class PrintRequestLogService { }); } - async findNextVersion(dtid: number): Promise { + async findNextVersion(dtid: number, documentType: string): Promise { + let fullDocumentType = ""; + switch (documentType) { + case ("LUR"): + fullDocumentType = "LAND USE REPORT"; + break; + case ("GL"): + fullDocumentType = "GRAZING LEASE"; + break; + default: + fullDocumentType = "LAND USE REPORT"; + break; + } const requestLogs = await this.printRequestLogRepository.findAndCount({ where: { dtid: dtid, + document_type: fullDocumentType }, }); let version = (requestLogs[1] + 1).toString(); diff --git a/frontend/public/js/util.js b/frontend/public/js/util.js index dd2dd3a8..52117d25 100644 --- a/frontend/public/js/util.js +++ b/frontend/public/js/util.js @@ -1,10 +1,10 @@ -async function generateReport() { +async function generateReport(documentType) { const tenureFileNumber = $("#tfn").text(); const prdid = $("#prdid").text(); const dtid = $("#dtid").text(); $("#genReport").prop("disabled", true); const reportName = await fetch( - `/report/get-report-name/${dtid}/${tenureFileNumber}`, + `/report/get-report-name/${dtid}/${tenureFileNumber}/${documentType}`, { method: "GET", headers: { @@ -20,12 +20,13 @@ async function generateReport() { .catch(() => { location.reload(); }); - const document_type = $("#document_type_id option:selected").text(); + console.log(reportName) const data = { prdid: prdid, - document_type: document_type, + dtid: dtid, + document_type: documentType, }; - fetch(`/report/generate-lur-report`, { + fetch(`/report/generate-report`, { method: "POST", headers: { "Content-Type": "application/json", diff --git a/frontend/src/app.controller.ts b/frontend/src/app.controller.ts index d79013c6..51edce6b 100644 --- a/frontend/src/app.controller.ts +++ b/frontend/src/app.controller.ts @@ -15,6 +15,7 @@ import { NFR_VARIANTS_ARRAY, PAGE_TITLES, REPORT_TYPES, + REPORT_URLS, } from "utils/constants"; import { SessionData } from "utils/types"; import { AuthenticationGuard } from "./authentication/authentication.guard"; @@ -99,7 +100,6 @@ export class AppController { @Req() request: Request, @Res() response: Response ) { - console.log("LUR"); const hasParams = request.originalUrl.includes("?session_state"); if (hasParams) { const urlWithoutParams = request.path; @@ -201,22 +201,16 @@ export class AppController { @Res() res: Response ) { const decodedDocumentType = decodeURIComponent(documentType).toUpperCase(); - console.log(decodedDocumentType); - console.log("888"); - console.log(documentType); - console.log("888"); const hasParams = req.originalUrl.includes("?session_state"); if (hasParams) { const urlWithoutParams = req.path; res.redirect(301, urlWithoutParams); } else if ( - !NFR_VARIANTS_ARRAY.includes(decodedDocumentType) && - decodedDocumentType != "GRAZINGLEASE" - ) { + !REPORT_URLS.includes(decodedDocumentType) ) { const redirectUrl = `/dtid/${dtid}`; res.redirect(301, redirectUrl); } else { - if (decodedDocumentType == "GRAZINGLEASE") { + if (decodedDocumentType == "GRAZING LEASE") { return this.getGrazingLeaseDisplayData(session, dtid, res); } else { return this.getNfrDisplayData(session, dtid, documentType, res); diff --git a/frontend/src/authentication/authentication.filter.ts b/frontend/src/authentication/authentication.filter.ts index c09f4601..18ff42af 100644 --- a/frontend/src/authentication/authentication.filter.ts +++ b/frontend/src/authentication/authentication.filter.ts @@ -18,7 +18,6 @@ export class AuthenticationFilter implements ExceptionFilter { keycloak_login_baseurl + "?" + keycloak_login_params; } catch(exception: any, host: ArgumentsHost) { - console.log(exception); if (exception.status == HttpStatus.UNAUTHORIZED) { console.log("unauth"); const ctx = host.switchToHttp(); diff --git a/frontend/src/report/report.controller.ts b/frontend/src/report/report.controller.ts index 0013bbf7..a6336987 100644 --- a/frontend/src/report/report.controller.ts +++ b/frontend/src/report/report.controller.ts @@ -42,12 +42,13 @@ export class ReportController { }; } - @Get("get-report-name/:dtid/:tfn") + @Get("get-report-name/:dtid/:tfn/:documentType") getReportName( @Param("dtid") dtid: number, - @Param("tfn") tenureFileNumber: string + @Param("tfn") tenureFileNumber: string, + @Param("documentType") documentType: string ): Promise<{ reportName: string }> { - return this.reportService.generateReportName(dtid, tenureFileNumber); + return this.reportService.generateReportName(dtid, tenureFileNumber, documentType); } @Get("get-nfr-report-name/:dtid/:tfn") @@ -58,15 +59,15 @@ export class ReportController { return this.reportService.generateNFRReportName(dtid, tenureFileNumber); } - @Post("generate-lur-report") + @Post("generate-report") @Header( "Content-Type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ) @Header("Content-Disposition", "attachment; filename=landusereport.docx") - async generateLURReport( + async generateReport( @Session() session: { data: SessionData }, - @Body() data: { prdid: string; document_type: string } + @Body() data: { prdid: string; document_type: string, dtid: number } ) { // this should eventually check permissions and prevent unauthorized users from generating documents let idir_username = ""; @@ -76,10 +77,15 @@ export class ReportController { } else { console.log("no active account found"); } - - return new StreamableFile( - await this.reportService.generateLURReport(+data.prdid, idir_username) - ); + if (data.document_type == 'GL') { + return new StreamableFile( + await this.reportService.generateGLReport(+data.dtid, idir_username) + ); + } else { + return new StreamableFile( + await this.reportService.generateLURReport(+data.prdid, idir_username) + ); + } } @Post("generate-nfr-report") diff --git a/frontend/src/report/report.service.ts b/frontend/src/report/report.service.ts index b0b4701a..5c3a2fc0 100644 --- a/frontend/src/report/report.service.ts +++ b/frontend/src/report/report.service.ts @@ -4,8 +4,8 @@ import * as dotenv from "dotenv"; import { firstValueFrom } from "rxjs"; import { TTLSService } from "src/ttls/ttls.service"; import { + GL_REPORT_TYPE, LUR_REPORT_TYPE, - REPORT_TYPES, numberWords, sectionTitles, } from "utils/constants"; @@ -13,7 +13,6 @@ import { ProvisionJSON, VariableJSON } from "utils/types"; import { convertToSpecialCamelCase, formatMoney, - formatPostalCode, nfrAddressBuilder, } from "utils/util"; const axios = require("axios"); @@ -25,7 +24,6 @@ let port: number; @Injectable() export class ReportService { constructor( - private readonly httpService: HttpService, private readonly ttlsService: TTLSService ) { hostname = process.env.backend_url @@ -43,8 +41,8 @@ export class ReportService { * @param tenureFileNumber * @returns */ - async generateReportName(dtid: number, tenureFileNumber: string) { - const url = `${hostname}:${port}/print-request-log/version/` + dtid; + async generateReportName(dtid: number, tenureFileNumber: string, documentType:string) { + const url = `${hostname}:${port}/print-request-log/version/${dtid}/${documentType}`; // grab the next version string for the dtid const version = await axios .get(url, { @@ -55,20 +53,19 @@ export class ReportService { .then((res) => { return res.data; }); - return { reportName: "LUR_" + tenureFileNumber + "_" + version }; + return { reportName: documentType + "_" + tenureFileNumber + "_" + version }; } /** - * Generates the Land use Report using CDOGS + * Generates the Land Use Report using CDOGS * * @param prdid - * @param document_type * @param username * @returns */ async generateLURReport(prdid: number, username: string) { const documentType = LUR_REPORT_TYPE; - const url = `${hostname}:${port}/print-request-detail/view/` + prdid; + const url = `${hostname}:${port}/print-request-detail/view/${prdid}`; const templateUrl = `${hostname}:${port}/document-template/get-active-report/${documentType}`; const logUrl = `${hostname}:${port}/print-request-log/`; @@ -116,7 +113,108 @@ export class ReportService { cacheReport: false, convertTo: "docx", overwrite: true, - reportName: "lur-report", + reportName: "ticdi-report", + }, + template: { + content: `${bufferBase64}`, + encodingType: "base64", + fileType: "docx", + }, + }); + + const conf = { + method: "post", + url: process.env.cdogs_url, + headers: { + Authorization: `Bearer ${cdogsToken}`, + "Content-Type": "application/json", + }, + responseType: "arraybuffer", + data: md, + }; + const ax = require("axios"); + const response = await ax(conf).catch((error) => { + console.log(error.response); + }); + return response.data; + } + + /** + * Generates the Land Use Report using CDOGS + * + * @param prdid + * @param username + * @returns + */ + async generateGLReport(dtid: number, username: string) { + const documentType = GL_REPORT_TYPE; + const templateUrl = `${hostname}:${port}/document-template/get-active-report/${documentType}`; + const logUrl = `${hostname}:${port}/print-request-log/`; + + // get raw ttls data for later + await this.ttlsService.setWebadeToken(); + const rawData: any = await firstValueFrom(this.ttlsService.callHttp(dtid)) + .then((res) => { + return res; + }) + .catch((err) => { + console.log(err); + }); + + // get the document template + const documentTemplateObject: { id: number; the_file: string } = await axios + .get(templateUrl) + .then((res) => { + return res.data; + }); + const interestParcel = rawData.interestParcel[0]; + const tenantAddr = rawData.tenantAddr; + + // TODO get these variables + const data = { + DB_File_Number: rawData.fileNum, + DB_Document_Number: dtid, + DB_Address_Street_Tenant: "PLACEHOLDER", + DB_Address_Regional_Office: nfrAddressBuilder([ + { + addrLine1: rawData.regOfficeStreet, + city: rawData.regOfficeCity, + provAbbr: rawData.regOfficeProv, + postalCode: rawData.regOfficePostalCode, + }, + ]), + DB_Address_Mailing_Tenant: tenantAddr[0] + ? nfrAddressBuilder(tenantAddr) + : "", + DB_Name_Tenant: this.ttlsService.getLicenceHolder(tenantAddr), + DB_Name_Corporation: tenantAddr.contactCompanyName, + DB_Legal_Description: interestParcel + ? interestParcel.legalDescription + : "", + }; + + // log the request + const document_template_id = documentTemplateObject.id; + await axios.post(logUrl, { + document_template_id: document_template_id, + print_request_detail_id: null, + document_type: documentType, + dtid: dtid, + request_app_user: username, + request_json: JSON.stringify(data), + }); + + const cdogsToken = await this.ttlsService.callGetToken(); + const bufferBase64 = documentTemplateObject.the_file; + const md = JSON.stringify({ + data, + formatters: + '{"myFormatter":"_function_myFormatter|function(data) { return data.slice(1); }","myOtherFormatter":"_function_myOtherFormatter|function(data) {return data.slice(2);}"}', + options: { + cacheReport: false, + convertTo: "docx", + overwrite: true, + reportName: "ticdi-report", }, template: { content: `${bufferBase64}`, diff --git a/frontend/utils/constants.ts b/frontend/utils/constants.ts index 9f44e752..f02b690c 100644 --- a/frontend/utils/constants.ts +++ b/frontend/utils/constants.ts @@ -9,6 +9,7 @@ export const PAGE_TITLES = { }; export const LUR_REPORT_TYPE = "LAND USE REPORT"; +export const GL_REPORT_TYPE = "GRAZING LEASE" // Used for admin page dropdown for manage templates page export const REPORT_TYPES = [ @@ -24,6 +25,14 @@ export const NFR_VARIANTS_ARRAY = [ "NOTICE OF FINAL REVIEW (SURVEY REQUIRED)", "NOTICE OF FINAL REVIEW (TO OBTAIN SURVEY)", ]; +export const REPORT_URLS = [ + "NOTICE OF FINAL REVIEW", + "NOTICE OF FINAL REVIEW (DELAYED)", + "NOTICE OF FINAL REVIEW (NO FEES)", + "NOTICE OF FINAL REVIEW (SURVEY REQUIRED)", + "NOTICE OF FINAL REVIEW (TO OBTAIN SURVEY)", + "GRAZING LEASE" +] export const NFR_VARIANTS_ARRAY_FORMATTED = [ "Notice of Final Review", "Notice of Final Review (Delayed)", diff --git a/frontend/views/pages/grazing-lease.hbs b/frontend/views/pages/grazing-lease.hbs index 8c2115ed..182e19fc 100644 --- a/frontend/views/pages/grazing-lease.hbs +++ b/frontend/views/pages/grazing-lease.hbs @@ -112,7 +112,7 @@ - Create + Create diff --git a/frontend/views/pages/index.hbs b/frontend/views/pages/index.hbs index 317ba291..51bbb3e1 100644 --- a/frontend/views/pages/index.hbs +++ b/frontend/views/pages/index.hbs @@ -112,7 +112,7 @@ - Create + Create From 1b656c2a45b3b5edfc8c4aba2cc008e5031d6f19 Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Tue, 31 Oct 2023 13:48:42 -0700 Subject: [PATCH 4/5] ticdi-45 fix and grazing lease vars --- frontend/src/report/report.service.ts | 34 +++---- frontend/utils/util.ts | 139 +++++++++++++++++++++++--- 2 files changed, 141 insertions(+), 32 deletions(-) diff --git a/frontend/src/report/report.service.ts b/frontend/src/report/report.service.ts index 5c3a2fc0..44ac11e5 100644 --- a/frontend/src/report/report.service.ts +++ b/frontend/src/report/report.service.ts @@ -13,6 +13,7 @@ import { ProvisionJSON, VariableJSON } from "utils/types"; import { convertToSpecialCamelCase, formatMoney, + grazingLeaseVariables, nfrAddressBuilder, } from "utils/util"; const axios = require("axios"); @@ -167,30 +168,27 @@ export class ReportService { .then((res) => { return res.data; }); - const interestParcel = rawData.interestParcel[0]; + const interestParcel = rawData.interestParcel; const tenantAddr = rawData.tenantAddr; + const regVars = + { + regOfficeStreet: rawData && rawData.regOfficeStreet ? rawData.regOfficeStreet : '', + regOfficeCity: rawData && rawData.regOfficeCity ? rawData.regOfficeCity : '', + regOfficeProv: rawData && rawData.regOfficeProv ? rawData.regOfficeProv : '', + regOfficePostalCode: rawData && rawData.regOfficePostalCode ? rawData.regOfficePostalCode : '' + } + const glVariables = grazingLeaseVariables(tenantAddr, interestParcel, regVars); // TODO get these variables const data = { DB_File_Number: rawData.fileNum, DB_Document_Number: dtid, - DB_Address_Street_Tenant: "PLACEHOLDER", - DB_Address_Regional_Office: nfrAddressBuilder([ - { - addrLine1: rawData.regOfficeStreet, - city: rawData.regOfficeCity, - provAbbr: rawData.regOfficeProv, - postalCode: rawData.regOfficePostalCode, - }, - ]), - DB_Address_Mailing_Tenant: tenantAddr[0] - ? nfrAddressBuilder(tenantAddr) - : "", - DB_Name_Tenant: this.ttlsService.getLicenceHolder(tenantAddr), - DB_Name_Corporation: tenantAddr.contactCompanyName, - DB_Legal_Description: interestParcel - ? interestParcel.legalDescription - : "", + DB_Address_Street_Tenant: glVariables.streetAddress, + DB_Address_Regional_Office: glVariables.addressRegionalOffice, + DB_Address_Mailing_Tenant: glVariables.mailingAddress, + DB_Name_Tenant: glVariables.mailingName, + DB_Name_Corporation: glVariables.mailingCorp, + DB_Legal_Description: glVariables.legalDescription, }; // log the request diff --git a/frontend/utils/util.ts b/frontend/utils/util.ts index 508372bf..d997a724 100644 --- a/frontend/utils/util.ts +++ b/frontend/utils/util.ts @@ -33,7 +33,7 @@ export function formatPostalCode(value: string) { * */ export function nfrAddressBuilder(tenantAddr: any[]): string { - const addressMap = new Map(); + const formattedAddresses: string[] = [] for (const addressObj of tenantAddr) { const { legalName, @@ -41,10 +41,13 @@ export function nfrAddressBuilder(tenantAddr: any[]): string { middleName, lastName, addrLine1, + addrLine2, + addrLine3, city, provAbbr, postalCode, } = addressObj; + console.log(addressObj) let name = null; @@ -57,6 +60,17 @@ export function nfrAddressBuilder(tenantAddr: any[]): string { ); name = filteredParts.join(" "); } + let addrLines = ''; + if (addrLine1 && addrLine1.length > 0) { + addrLines = addrLine1; + } + if (addrLine2 && addrLine2.length > 0) { + addrLines = [addrLines, addrLine2].join('\n'); + } + if (addrLine3 && addrLine3.length > 0) { + addrLines = [addrLines, addrLine3].join('\n'); + } + const parts = []; if (city) { parts.push(city); @@ -69,24 +83,121 @@ export function nfrAddressBuilder(tenantAddr: any[]): string { } const address = parts.join(" "); - const key = [addrLine1, address].join(","); - if (!addressMap.has(key)) { - addressMap.set(key, []); - } + // combine name, addrLines, and address + formattedAddresses.push([name, addrLines, address].join('\n')); + } + return formattedAddresses.join("\n"); +} - const addressParts = []; - if (name) { - addressParts.push(name); +export function grazingLeaseVariables(tenantAddr: [{ + addrLine1: string; + addrLine2: string; + addrLine3: string; + addrType: string; + firstName: string; + middleName: string; + lastName: string; + legalName: string; +}], interestParcel: [{ + legalDescription: string; +}], regVars: {regOfficeStreet: string, regOfficeCity: string, regOfficeProv: string, regOfficePostalCode: string}): +{streetAddress: string; streetName: string; streetCorp: string; mailingAddress: string; mailingName: string; mailingCorp: string; legalDescription: string; addressRegionalOffice: string} { + let streetAddress = ''; + let streetName = ''; + let streetCorp = ''; + let mailingAddress = ''; + let mailingName = ''; + let mailingCorp = ''; + let legalDescription = ''; + let addressRegionalOffice = ''; + + if (tenantAddr) { + for (let tenant of tenantAddr) { + if (tenant.addrType == 'MAILING') { + const tempMailingAddress = getMailingAddress(tenant); + mailingAddress = mailingAddress.length > 0 ? [mailingAddress, tempMailingAddress].join('\n ') : tempMailingAddress; + const tempMailingName = getFullName(tenant); + mailingName = mailingName.length > 0 ? [mailingName, tempMailingName].join('\n ') : tempMailingName; + const tempMailingCorp = getCorp(tenant); + mailingCorp = mailingCorp.length > 0 ? [mailingCorp, tempMailingCorp].join('\n ') : tempMailingCorp; + } else if (tenant.addrType == 'STREET') { + const tempStreetAddress = getMailingAddress(tenant); + streetAddress = streetAddress.length > 0 ? [streetAddress, tempStreetAddress].join('\n ') : tempStreetAddress; + const tempStreetName = getFullName(tenant); + streetName = streetName.length > 0 ? [streetName, tempStreetName].join('\n ') : tempStreetName; + const tempStreetCorp = getCorp(tenant); + streetCorp = streetCorp.length > 0 ? [streetCorp, tempStreetCorp].join('\n ') : tempStreetCorp; + } + } + + // if either address is empty, set it to the other + if (mailingAddress.length == 0) { + mailingAddress = streetAddress; + } + if (streetAddress.length == 0) { + streetAddress = mailingAddress; + } + // if either name is empty, set it to the other + if (mailingName.length == 0) { + mailingName = streetName; + } + if (streetName.length == 0) { + streetName = mailingName; + } + // if either corp is empty, set it to the other + if (mailingCorp.length == 0) { + mailingCorp = streetCorp; } - addressMap.get(key)?.push(addressParts.join("\n")); + if (streetCorp.length == 0) { + streetCorp = mailingCorp; + } + } + if (interestParcel) { + for (let parcel of interestParcel) { + const tempLegalDescription = parcel.legalDescription; + legalDescription = legalDescription.length > 0 ? [legalDescription, tempLegalDescription].join('\n ') : tempLegalDescription; + } + } + if (regVars.regOfficeStreet.length > 0) { + addressRegionalOffice = regVars.regOfficeStreet; + } + if (regVars.regOfficeCity.length > 0) { + addressRegionalOffice = [addressRegionalOffice, regVars.regOfficeCity].join(', '); } + if (regVars.regOfficeProv.length > 0) { + addressRegionalOffice = [addressRegionalOffice, regVars.regOfficeProv].join(', '); + } + if (regVars.regOfficePostalCode.length > 0) { + addressRegionalOffice = [addressRegionalOffice, regVars.regOfficePostalCode].join(', '); + } + + return {streetAddress, streetName, streetCorp, mailingAddress, mailingName, mailingCorp, legalDescription, addressRegionalOffice} +} - const formattedAddresses: string[] = []; - for (const [key, addresses] of addressMap.entries()) { - const [addrLine1, cityProvAbbrPostalCode] = key.split(","); - formattedAddresses.push(...addresses, addrLine1, cityProvAbbrPostalCode); +function getFullName(tenant: { + firstName: string; + middleName: string; + lastName: string; +}): string { + const nameParts = []; + if (tenant.firstName !== null) { + nameParts.push(tenant.firstName); } - return formattedAddresses.join("\n"); + if (tenant.middleName !== null) { + nameParts.push(tenant.middleName); + } + if (tenant.lastName !== null) { + nameParts.push(tenant.lastName); + } + const fullName = nameParts.join(' '); + + return fullName; +} + +function getCorp(tenant: { + legalName: string; +}): string { + return tenant.legalName??''; } export function getMailingAddress(tenantAddr: { From 9ec16783b42e8db8f574e4872b22b3e1684ef635 Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Tue, 31 Oct 2023 13:58:18 -0700 Subject: [PATCH 5/5] there was already a ticdi-45 fix --- frontend/utils/util.ts | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/frontend/utils/util.ts b/frontend/utils/util.ts index d997a724..064417c1 100644 --- a/frontend/utils/util.ts +++ b/frontend/utils/util.ts @@ -33,7 +33,7 @@ export function formatPostalCode(value: string) { * */ export function nfrAddressBuilder(tenantAddr: any[]): string { - const formattedAddresses: string[] = [] + const formattedAddresses: string[] = []; for (const addressObj of tenantAddr) { const { legalName, @@ -47,10 +47,9 @@ export function nfrAddressBuilder(tenantAddr: any[]): string { provAbbr, postalCode, } = addressObj; - console.log(addressObj) + const formattedAddress: string[] = []; let name = null; - if (legalName) { name = legalName; } else if (firstName || middleName || lastName) { @@ -60,16 +59,6 @@ export function nfrAddressBuilder(tenantAddr: any[]): string { ); name = filteredParts.join(" "); } - let addrLines = ''; - if (addrLine1 && addrLine1.length > 0) { - addrLines = addrLine1; - } - if (addrLine2 && addrLine2.length > 0) { - addrLines = [addrLines, addrLine2].join('\n'); - } - if (addrLine3 && addrLine3.length > 0) { - addrLines = [addrLines, addrLine3].join('\n'); - } const parts = []; if (city) { @@ -83,8 +72,12 @@ export function nfrAddressBuilder(tenantAddr: any[]): string { } const address = parts.join(" "); - // combine name, addrLines, and address - formattedAddresses.push([name, addrLines, address].join('\n')); + formattedAddress.push(name); + if (addrLine1) formattedAddress.push(addrLine1); + if (addrLine2) formattedAddress.push(addrLine2); + if (addrLine3) formattedAddress.push(addrLine3); + formattedAddress.push(address); + formattedAddresses.push(formattedAddress.join("\n")); } return formattedAddresses.join("\n"); }