From b85cd7bcc71e03c694fbd324f60ef2bb71cc777f Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:04:39 -0800 Subject: [PATCH 1/2] update to fix & import fix --- frontend/src/admin/admin.service.ts | 234 +++++++++++--------------- frontend/src/report/report.service.ts | 14 +- 2 files changed, 103 insertions(+), 145 deletions(-) diff --git a/frontend/src/admin/admin.service.ts b/frontend/src/admin/admin.service.ts index 4e414baa..fd6fcbb2 100644 --- a/frontend/src/admin/admin.service.ts +++ b/frontend/src/admin/admin.service.ts @@ -1,10 +1,10 @@ -import { Injectable } from "@nestjs/common"; -import * as dotenv from "dotenv"; -import { HttpService } from "@nestjs/axios"; -import { ExportDataObject, SearchResultsItem, UserObject } from "utils/types"; -import { REPORT_TYPES } from "utils/constants"; -const axios = require("axios"); -const FormData = require("form-data"); +import { Injectable } from '@nestjs/common'; +import * as dotenv from 'dotenv'; +import { HttpService } from '@nestjs/axios'; +import { ExportDataObject, SearchResultsItem, UserObject } from '../../utils/types'; +import { REPORT_TYPES } from '../../utils/constants'; +const axios = require('axios'); +const FormData = require('form-data'); dotenv.config(); let hostname: string; @@ -13,18 +13,12 @@ let port: number; @Injectable() export class AdminService { constructor(private readonly httpService: HttpService) { - hostname = process.env.backend_url - ? process.env.backend_url - : `http://localhost`; + hostname = process.env.backend_url ? process.env.backend_url : `http://localhost`; // local development backend port is 3001, docker backend port is 3000 port = process.env.backend_url ? 3000 : 3001; } - async activateTemplate(data: { - id: number; - update_userid: string; - document_type: string; - }): Promise { + async activateTemplate(data: { id: number; update_userid: string; document_type: string }): Promise { const url = `${hostname}:${port}/document-template/activate-template`; return axios .post(url, { @@ -45,9 +39,7 @@ export class AdminService { } async removeTemplate(reportType: string, id: number): Promise { - const url = `${hostname}:${port}/document-template/remove/${encodeURI( - reportType - )}/${id}`; + const url = `${hostname}:${port}/document-template/remove/${encodeURI(reportType)}/${id}`; return axios.get(url).then((res) => { return res.data; }); @@ -66,13 +58,13 @@ export class AdminService { ): Promise { const url = `${hostname}:${port}/document-template/create`; const form: any = new FormData(); - form.append("document_type", data.document_type); - form.append("active_flag", data.active_flag); - form.append("mime_type", data.mime_type); - form.append("file_name", data.file_name); - form.append("template_author", data.template_author); - form.append("create_userid", data.create_userid); - form.append("file", file.buffer, "file"); + form.append('document_type', data.document_type); + form.append('active_flag', data.active_flag); + form.append('mime_type', data.mime_type); + form.append('file_name', data.file_name); + form.append('template_author', data.template_author); + form.append('create_userid', data.create_userid); + form.append('file', file.buffer, 'file'); return axios.post(url, form).then((res) => { return res.data; }); @@ -81,15 +73,15 @@ export class AdminService { async getToken() { const url = process.env.users_api_token_url; const token = `${process.env.users_api_client_id}:${process.env.users_api_client_secret}`; - const encodedToken = Buffer.from(token).toString("base64"); + const encodedToken = Buffer.from(token).toString('base64'); const config = { headers: { - "Content-Type": "application/x-www-form-urlencoded", - Authorization: "Basic " + encodedToken, + 'Content-Type': 'application/x-www-form-urlencoded', + Authorization: 'Basic ' + encodedToken, }, }; const grantTypeParam = new URLSearchParams(); - grantTypeParam.append("grant_type", "client_credentials"); + grantTypeParam.append('grant_type', 'client_credentials'); return axios .post(url, grantTypeParam, config) .then((response) => { @@ -118,27 +110,27 @@ export class AdminService { const bearerToken = await this.getToken(); const searchData: SearchResultsItem[] = await axios .get(url, { - headers: { Authorization: "Bearer " + bearerToken }, + headers: { Authorization: 'Bearer ' + bearerToken }, }) .then((res) => { return res.data.data; }) .catch((err) => { console.log(err.response.data); - throw new Error("No users found"); + throw new Error('No users found'); }); - const firstName = searchData[0].firstName ? searchData[0].firstName : ""; - const lastName = searchData[0].lastName ? searchData[0].lastName : ""; + const firstName = searchData[0].firstName ? searchData[0].firstName : ''; + const lastName = searchData[0].lastName ? searchData[0].lastName : ''; const username = searchData[0].attributes ? searchData[0].attributes.idir_username[0] ? searchData[0].attributes.idir_username[0] - : "" - : ""; + : '' + : ''; const idirUsername = searchData[0].attributes ? searchData[0].attributes.idir_user_guid[0] ? searchData[0].attributes.idir_user_guid[0] - : "" - : ""; + : '' + : ''; const userObject = { firstName: firstName, lastName: lastName, @@ -148,7 +140,7 @@ export class AdminService { const roleUrl = `${process.env.users_api_base_url}/integrations/${process.env.integration_id}/${process.env.css_environment}/users/${idirUsername}@idir/roles`; const roles = await axios .get(roleUrl, { - headers: { Authorization: "Bearer " + bearerToken }, + headers: { Authorization: 'Bearer ' + bearerToken }, }) .then((res) => { return res.data; @@ -159,12 +151,12 @@ export class AdminService { }); let isAdmin: boolean = false; for (let entry of roles.data) { - if (entry && entry.name == "ticdi_admin") { + if (entry && entry.name == 'ticdi_admin') { isAdmin = true; } } if (isAdmin) { - throw new Error("That user is already a TICDI admin"); + throw new Error('That user is already a TICDI admin'); } return userObject; } @@ -184,34 +176,34 @@ export class AdminService { const bearerToken = await this.getToken(); const searchData: SearchResultsItem[] = await axios .get(url, { - headers: { Authorization: "Bearer " + bearerToken }, + headers: { Authorization: 'Bearer ' + bearerToken }, }) .then((res) => { return res.data.data; }) .catch((err) => console.log(err.response.data)); if (searchData.length > 1) { - throw new Error("More than one user was found"); + throw new Error('More than one user was found'); } else if (searchData.length == 0) { - throw new Error("No users were found"); + throw new Error('No users were found'); } const userObject: UserObject = this.formatSearchData(searchData)[0]; await axios .post( addAdminUrl, { - roleName: "ticdi_admin", - username: userObject.idirUsername + "@idir", - operation: "add", + roleName: 'ticdi_admin', + username: userObject.idirUsername + '@idir', + operation: 'add', }, - { headers: { Authorization: "Bearer " + bearerToken } } + { headers: { Authorization: 'Bearer ' + bearerToken } } ) .then((res) => { return res.data; }) .catch((err) => { console.log(err); - throw new Error("Failed to add admin role"); + throw new Error('Failed to add admin role'); }); return userObject; } @@ -226,7 +218,7 @@ export class AdminService { const url = `${process.env.users_api_base_url}/integrations/${process.env.integration_id}/${process.env.css_environment}/roles/ticdi_admin/users`; const data: SearchResultsItem[] = await axios .get(url, { - headers: { Authorization: "Bearer " + bearerToken }, + headers: { Authorization: 'Bearer ' + bearerToken }, }) .then((res) => { return res.data.data; @@ -241,7 +233,7 @@ export class AdminService { const url = `${process.env.users_api_base_url}/integrations/${process.env.integration_id}/${process.env.css_environment}/roles/ticdi_admin/users`; const data: SearchResultsItem[] = await axios .get(url, { - headers: { Authorization: "Bearer " + bearerToken }, + headers: { Authorization: 'Bearer ' + bearerToken }, }) .then((res) => { return res.data.data; @@ -258,29 +250,26 @@ export class AdminService { * @returns null */ async removeAdmin(username: string) { - const ticdiAdminRole = "ticdi_admin"; + const ticdiAdminRole = 'ticdi_admin'; const bearerToken = await this.getToken(); const url = `${process.env.users_api_base_url}/integrations/${process.env.integration_id}/${process.env.css_environment}/users/${username}@idir/roles/${ticdiAdminRole}`; const res = await axios .delete(url, { - headers: { Authorization: "Bearer " + bearerToken }, + headers: { Authorization: 'Bearer ' + bearerToken }, }) .then((res) => { return res; }) .catch((err) => { console.log(err.response.data); - return { message: "Failed to remove admin privileges" }; + return { message: 'Failed to remove admin privileges' }; }); - return { message: "success" }; + return { message: 'success' }; } async getTemplates(reportId: number) { - const documentType = - reportId == 1 || reportId == 2 ? REPORT_TYPES[reportId - 1] : "none"; - const url = `${hostname}:${port}/document-template/${encodeURI( - documentType - )}`; + const documentType = reportId == 1 || reportId == 2 ? REPORT_TYPES[reportId - 1] : 'none'; + const url = `${hostname}:${port}/document-template/${encodeURI(documentType)}`; const data = await axios .get(url) .then((res) => { @@ -299,8 +288,8 @@ export class AdminService { const document = { version: entry.template_version, file_name: entry.file_name, - updated_date: entry.update_timestamp.split("T")[0], - status: "???", + updated_date: entry.update_timestamp.split('T')[0], + status: '???', active: entry.active_flag, template_id: entry.id, }; @@ -310,17 +299,8 @@ export class AdminService { } async getDocumentTemplates(documentType: string): Promise { - const returnItems = [ - "id", - "template_version", - "file_name", - "uploaded_date", - "active_flag", - "update_timestamp", - ]; - const url = `${hostname}:${port}/document-template/${encodeURI( - documentType - )}`; + const returnItems = ['id', 'template_version', 'file_name', 'uploaded_date', 'active_flag', 'update_timestamp']; + const url = `${hostname}:${port}/document-template/${encodeURI(documentType)}`; const documentTemplateObjects = await axios .get(url) .then((res) => { @@ -332,29 +312,27 @@ export class AdminService { .filter((key) => returnItems.includes(key)) .reduce( (acc, key) => { - key == "update_timestamp" - ? (acc[key] = obj[key].split("T")[0]) - : (acc[key] = obj[key]); + key == 'update_timestamp' ? (acc[key] = obj[key].split('T')[0]) : (acc[key] = obj[key]); return acc; }, - { view: "view", remove: "remove" } + { view: 'view', remove: 'remove' } ) ); } async getNFRProvisions(): Promise { const returnItems = [ - "id", - "dtid", - "type", - "provision_group", - "max", - "provision_name", - "free_text", - "help_text", - "category", - "active_flag", - "variants", + 'id', + 'dtid', + 'type', + 'provision_group', + 'max', + 'provision_name', + 'free_text', + 'help_text', + 'category', + 'active_flag', + 'variants', ]; const url = `${hostname}:${port}/nfr-provision`; const nfrProvisions = await axios @@ -371,19 +349,13 @@ export class AdminService { acc[key] = obj[key]; return acc; }, - { edit: "edit" } + { edit: 'edit' } ) ); } async getNFRVariables(): Promise { - const returnItems = [ - "variable_name", - "variable_value", - "help_text", - "id", - "provision_id", - ]; + const returnItems = ['variable_name', 'variable_value', 'help_text', 'id', 'provision_id']; const url = `${hostname}:${port}/nfr-provision/variables`; const nfrVariables = await axios .get(url) @@ -399,7 +371,7 @@ export class AdminService { acc[key] = obj[key]; return acc; }, - { edit: "edit", remove: "remove" } + { edit: 'edit', remove: 'remove' } ) ); } @@ -440,11 +412,9 @@ export class AdminService { create_userid: string ) { const url = `${hostname}:${port}/nfr-provision`; - return await axios - .post(url, { ...provisionParams, create_userid }) - .then((res) => { - return res.data; - }); + return await axios.post(url, { ...provisionParams, create_userid }).then((res) => { + return res.data; + }); } async updateProvision( @@ -463,11 +433,9 @@ export class AdminService { update_userid: string ) { const url = `${hostname}:${port}/nfr-provision/update`; - return await axios - .post(url, { ...provisionParams, update_userid }) - .then((res) => { - return res.data; - }); + return await axios.post(url, { ...provisionParams, update_userid }).then((res) => { + return res.data; + }); } async addVariable( @@ -480,11 +448,9 @@ export class AdminService { create_userid: string ) { const url = `${hostname}:${port}/nfr-provision/add-variable`; - return await axios - .post(url, { ...variableParams, create_userid }) - .then((res) => { - return res.data; - }); + return await axios.post(url, { ...variableParams, create_userid }).then((res) => { + return res.data; + }); } async updateVariable( @@ -497,11 +463,9 @@ export class AdminService { update_userid: string ) { const url = `${hostname}:${port}/nfr-provision/update-variable`; - return await axios - .post(url, { ...variableParams, update_userid }) - .then((res) => { - return res.data; - }); + return await axios.post(url, { ...variableParams, update_userid }).then((res) => { + return res.data; + }); } async removeVariable(id: number) { @@ -518,20 +482,16 @@ export class AdminService { formatSearchData(data: SearchResultsItem[]): UserObject[] { let userObjectArray = []; for (let entry of data) { - const firstName = entry.firstName ? entry.firstName : ""; - const lastName = entry.lastName ? entry.lastName : ""; - const username = entry.attributes.idir_username[0] - ? entry.attributes.idir_username[0] - : ""; - const email = entry.email ? entry.email : ""; - const idirUsername = entry.username - ? entry.username.replace("@idir", "") - : ""; + const firstName = entry.firstName ? entry.firstName : ''; + const lastName = entry.lastName ? entry.lastName : ''; + const username = entry.attributes.idir_username[0] ? entry.attributes.idir_username[0] : ''; + const email = entry.email ? entry.email : ''; + const idirUsername = entry.username ? entry.username.replace('@idir', '') : ''; const userObject: UserObject = { - name: firstName + " " + lastName, + name: firstName + ' ' + lastName, username: username, email: email, - remove: "Remove", + remove: 'Remove', idirUsername: idirUsername, }; userObjectArray.push(userObject); @@ -547,19 +507,13 @@ export class AdminService { formatExportData(data: SearchResultsItem[]): ExportDataObject[] { let exportDataObjectArray = []; for (let entry of data) { - let firstName = entry.firstName ? entry.firstName : ""; - let lastName = entry.lastName ? entry.lastName : ""; - let username = entry.username ? entry.username : ""; - let email = entry.email ? entry.email : ""; - let idir_user_guid = entry.attributes.idir_user_guid[0] - ? entry.attributes.idir_user_guid[0] - : ""; - let idir_username = entry.attributes.idir_username[0] - ? entry.attributes.idir_username[0] - : ""; - let display_name = entry.attributes.display_name[0] - ? entry.attributes.display_name[0] - : ""; + let firstName = entry.firstName ? entry.firstName : ''; + let lastName = entry.lastName ? entry.lastName : ''; + let username = entry.username ? entry.username : ''; + let email = entry.email ? entry.email : ''; + let idir_user_guid = entry.attributes.idir_user_guid[0] ? entry.attributes.idir_user_guid[0] : ''; + let idir_username = entry.attributes.idir_username[0] ? entry.attributes.idir_username[0] : ''; + let display_name = entry.attributes.display_name[0] ? entry.attributes.display_name[0] : ''; const exportDataObject: ExportDataObject = { firstName: '"' + firstName + '"', lastName: '"' + lastName + '"', diff --git a/frontend/src/report/report.service.ts b/frontend/src/report/report.service.ts index f5a23137..d153e365 100644 --- a/frontend/src/report/report.service.ts +++ b/frontend/src/report/report.service.ts @@ -2,9 +2,9 @@ import { Injectable } from '@nestjs/common'; import * as dotenv from 'dotenv'; import { firstValueFrom } from 'rxjs'; import { TTLSService } from 'src/ttls/ttls.service'; -import { GL_REPORT_TYPE, LUR_REPORT_TYPE, numberWords, sectionTitles } from 'utils/constants'; -import { ProvisionJSON, VariableJSON } from 'utils/types'; -import { convertToSpecialCamelCase, formatMoney, grazingLeaseVariables, nfrAddressBuilder } from 'utils/util'; +import { GL_REPORT_TYPE, LUR_REPORT_TYPE, numberWords, sectionTitles } from '../../utils/constants'; +import { ProvisionJSON, VariableJSON } from '../../utils/types'; +import { convertToSpecialCamelCase, formatMoney, grazingLeaseVariables, nfrAddressBuilder } from '../../utils/util'; const axios = require('axios'); dotenv.config(); @@ -352,9 +352,13 @@ export class ReportService { if (interestParcels && interestParcels.length > 0) { let legalDescArray = []; for (let ip of interestParcels) { - legalDescArray.push(ip.legalDescription); + if (ip.legalDescription && ip.legalDescription != '') { + legalDescArray.push(ip.legalDescription); + } + } + if (legalDescArray.length > 0) { + concatLegalDescriptions = legalDescArray.join('\n'); } - concatLegalDescriptions = legalDescArray.join('\n'); } const DB_Address_Mailing_Tenant = tenantAddr[0] ? nfrAddressBuilder(tenantAddr) : ''; From 7f786fc87176b781d5b48fb6179501e7d9fc5815 Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:05:02 -0800 Subject: [PATCH 2/2] import fix --- frontend/src/app.controller.ts | 334 +++++++++++---------------------- 1 file changed, 114 insertions(+), 220 deletions(-) diff --git a/frontend/src/app.controller.ts b/frontend/src/app.controller.ts index 4cf34cf2..40aaf80e 100644 --- a/frontend/src/app.controller.ts +++ b/frontend/src/app.controller.ts @@ -1,33 +1,17 @@ -import { - Get, - Controller, - Render, - Param, - UseGuards, - UseFilters, - Session, - Query, - Res, -} from "@nestjs/common"; -import { AppService } from "./app.service"; -import { - NFR_VARIANTS, - NFR_VARIANTS_ARRAY, - PAGE_TITLES, - REPORT_TYPES, - REPORT_URLS, -} from "utils/constants"; -import { SessionData } from "utils/types"; -import { AuthenticationGuard } from "./authentication/authentication.guard"; -import { AuthenticationFilter } from "./authentication/authentication.filter"; -import { TTLSService } from "./ttls/ttls.service"; -import { AdminGuard } from "./admin/admin.guard"; -import { AxiosRequestConfig } from "axios"; -import { firstValueFrom } from "rxjs"; -import { Req } from "@nestjs/common/decorators/http/route-params.decorator"; -import { Request, Response } from "express"; -import { ReportService } from "./report/report.service"; -import { nfrInterestedParties } from "utils/util"; +import { Get, Controller, Render, Param, UseGuards, UseFilters, Session, Query, Res } from '@nestjs/common'; +import { AppService } from './app.service'; +import { NFR_VARIANTS, NFR_VARIANTS_ARRAY, PAGE_TITLES, REPORT_TYPES } from '../utils/constants'; +import { SessionData } from '../utils/types'; +import { AuthenticationGuard } from './authentication/authentication.guard'; +import { AuthenticationFilter } from './authentication/authentication.filter'; +import { TTLSService } from './ttls/ttls.service'; +import { AdminGuard } from './admin/admin.guard'; +import { AxiosRequestConfig } from 'axios'; +import { firstValueFrom } from 'rxjs'; +import { Req } from '@nestjs/common/decorators/http/route-params.decorator'; +import { Request, Response } from 'express'; +import { ReportService } from './report/report.service'; +import { nfrInterestedParties } from '../utils/util'; // let requestUrl: string; @@ -40,51 +24,40 @@ export class AppController { private readonly reportService: ReportService, private readonly ttlsService: TTLSService ) { - const hostname = process.env.backend_url - ? process.env.backend_url - : `http://localhost`; + const hostname = process.env.backend_url ? process.env.backend_url : `http://localhost`; const port = process.env.backend_url ? 3000 : 3001; requestUrl = `${hostname}:${port}/document-template/`; requestConfig = { headers: { - "Content-Type": "application/json", + 'Content-Type': 'application/json', }, }; } @Get() - @Render("index") + @Render('index') @UseFilters(AuthenticationFilter) @UseGuards(AuthenticationGuard) async root(@Session() session: { data?: SessionData }) { let isAdmin = false; - if ( - session.data && - session.data.activeAccount && - session.data.activeAccount.client_roles - ) { + if (session.data && session.data.activeAccount && session.data.activeAccount.client_roles) { for (let role of session.data.activeAccount.client_roles) { - if (role == "ticdi_admin") { + if (role == 'ticdi_admin') { isAdmin = true; } } } - const displayAdmin = isAdmin ? "Administration" : "-"; + const displayAdmin = isAdmin ? 'Administration' : '-'; const title = - process.env.ticdi_environment == "DEVELOPMENT" - ? "DEVELOPMENT - " + PAGE_TITLES.INDEX - : PAGE_TITLES.INDEX; + process.env.ticdi_environment == 'DEVELOPMENT' ? 'DEVELOPMENT - ' + PAGE_TITLES.INDEX : PAGE_TITLES.INDEX; return { title: title, - idirUsername: session.data.activeAccount - ? session.data.activeAccount.idir_username - : "", - primaryContactName: "", + idirUsername: session.data.activeAccount ? session.data.activeAccount.idir_username : '', + primaryContactName: '', displayAdmin: displayAdmin, }; } - /** * Renders the non-LUR report pages * @@ -93,23 +66,23 @@ export class AppController { * @param documentType * @returns */ - @Get("dtid/:dtid/:documentType") + @Get('dtid/:dtid/:documentType') @UseFilters(AuthenticationFilter) @UseGuards(AuthenticationGuard) async reportPage( @Session() session: { data?: SessionData }, - @Param("dtid") dtid: number, - @Param("documentType") documentType, + @Param('dtid') dtid: number, + @Param('documentType') documentType, @Req() req: Request, @Res() res: Response ) { - console.log('Report page document type: '+documentType); - let decodedDocumentType = decodeURIComponent(documentType) - decodedDocumentType = decodedDocumentType.toUpperCase().replace(/\s+/g, "").replace(/-/g, "").replace(/–/g,""); - console.log(decodedDocumentType) - if (decodedDocumentType == "GRAZINGLEASE" || decodedDocumentType == "AGRICULTURALLEASEUGRAZINGMP") { + console.log('Report page document type: ' + documentType); + let decodedDocumentType = decodeURIComponent(documentType); + decodedDocumentType = decodedDocumentType.toUpperCase().replace(/\s+/g, '').replace(/-/g, '').replace(/–/g, ''); + console.log(decodedDocumentType); + if (decodedDocumentType == 'GRAZINGLEASE' || decodedDocumentType == 'AGRICULTURALLEASEUGRAZINGMP') { return this.getGrazingLeaseDisplayData(session, dtid, res); - } else if (decodedDocumentType.includes("NOTICEOFFINALREVIEW")){ + } else if (decodedDocumentType.includes('NOTICEOFFINALREVIEW')) { return this.getNfrDisplayData(session, dtid, documentType, res); } else { return this.landUseReportPage(session, dtid, req, res); @@ -123,11 +96,12 @@ export class AppController { * @param id * @returns */ - @Get("dtid/:dtid") + @Get('dtid/:dtid') @UseFilters(AuthenticationFilter) @UseGuards(AuthenticationGuard) - async landUserReportRedirect(@Session() session: {data?:SessionData}, - @Param("dtid") dtid, + async landUserReportRedirect( + @Session() session: { data?: SessionData }, + @Param('dtid') dtid, @Req() req: Request, @Res() res: Response ) { @@ -138,116 +112,86 @@ export class AppController { @UseGuards(AuthenticationGuard) async landUseReportPage( @Session() session: { data?: SessionData }, - @Param("dtid") dtid, + @Param('dtid') dtid, @Req() req: Request, @Res() res: Response ) { - console.log('LUR report!') + console.log('LUR report!'); let isAdmin = false; - if ( - session.data && - session.data.activeAccount && - session.data.activeAccount.client_roles - ) { + if (session.data && session.data.activeAccount && session.data.activeAccount.client_roles) { for (let role of session.data.activeAccount.client_roles) { - if (role == "ticdi_admin") { + if (role == 'ticdi_admin') { isAdmin = true; } } } const title = - process.env.ticdi_environment == "DEVELOPMENT" - ? "DEVELOPMENT - " + PAGE_TITLES.INDEX - : PAGE_TITLES.INDEX; - const displayAdmin = isAdmin ? "Administration" : "-"; + process.env.ticdi_environment == 'DEVELOPMENT' ? 'DEVELOPMENT - ' + PAGE_TITLES.INDEX : PAGE_TITLES.INDEX; + const displayAdmin = isAdmin ? 'Administration' : '-'; await this.ttlsService.setWebadeToken(); let ttlsJSON, primaryContactName; try { - const response: any = await firstValueFrom( - this.ttlsService.callHttp(dtid) - ) + const response: any = await firstValueFrom(this.ttlsService.callHttp(dtid)) .then((res) => { return res; }) .catch((err) => { - console.log("callHttp failed"); + console.log('callHttp failed'); console.log(err); console.log(err.response.data); }); ttlsJSON = await this.ttlsService.sendToBackend(response); - ttlsJSON["cityProvPostal"] = this.ttlsService.concatCityProvPostal( + 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() - ); + ttlsJSON['inspected_date'] = this.ttlsService.formatInspectedDate(ttlsJSON.inspected_date.toString()); } primaryContactName = ttlsJSON.licence_holder_name; - return res.render("index", { + return res.render('index', { title: title, - idirUsername: session.data.activeAccount - ? session.data.activeAccount.idir_username - : "", + idirUsername: session.data.activeAccount ? session.data.activeAccount.idir_username : '', primaryContactName: primaryContactName, displayAdmin: displayAdmin, message: ttlsJSON, - documentTypes: [ - "Land Use Report", - "Notice of Final Review", - "Grazing Lease", - ], + documentTypes: ['Land Use Report', 'Notice of Final Review', 'Grazing Lease'], prdid: ttlsJSON.id, }); } catch (err) { console.log(err); - return res.render("index",{ + return res.render('index', { title: title, - idirUsername: session.data.activeAccount - ? session.data.activeAccount.idir_username - : "", + idirUsername: session.data.activeAccount ? session.data.activeAccount.idir_username : '', primaryContactName: primaryContactName ? primaryContactName : null, displayAdmin: displayAdmin, message: ttlsJSON ? ttlsJSON : null, - documentTypes: [ - "Land Use Report", - "Notice of Final Review", - "Grazing Lease", - ], + documentTypes: ['Land Use Report', 'Notice of Final Review', 'Grazing Lease'], prdid: ttlsJSON ? ttlsJSON.id : null, error: err, }); } } - @Get("system-admin") - @Render("system-admin") + @Get('system-admin') + @Render('system-admin') @UseFilters(AuthenticationFilter) @UseGuards(AuthenticationGuard) @UseGuards(AdminGuard) async systemAdminPage(@Session() session: { data?: SessionData }) { let isAdmin = false; - if ( - session.data && - session.data.activeAccount && - session.data.activeAccount.client_roles - ) { + if (session.data && session.data.activeAccount && session.data.activeAccount.client_roles) { for (let role of session.data.activeAccount.client_roles) { - if (role == "ticdi_admin") { + if (role == 'ticdi_admin') { isAdmin = true; } } } - const displayAdmin = isAdmin ? "Administration" : "-"; + const displayAdmin = isAdmin ? 'Administration' : '-'; const title = - process.env.ticdi_environment == "DEVELOPMENT" - ? "DEVELOPMENT - " + PAGE_TITLES.ADMIN - : PAGE_TITLES.ADMIN; + process.env.ticdi_environment == 'DEVELOPMENT' ? 'DEVELOPMENT - ' + PAGE_TITLES.ADMIN : PAGE_TITLES.ADMIN; return { title: title, - idirUsername: session.data.activeAccount - ? session.data.activeAccount.idir_username - : "", + idirUsername: session.data.activeAccount ? session.data.activeAccount.idir_username : '', displayAdmin: displayAdmin, reportTypes: [ { reportType: REPORT_TYPES[0], reportIndex: 1 }, @@ -257,31 +201,24 @@ export class AppController { }; } - @Get("manage-templates") - @Render("manage-templates") + @Get('manage-templates') + @Render('manage-templates') @UseFilters(AuthenticationFilter) @UseGuards(AuthenticationGuard) @UseGuards(AdminGuard) - async adminPage( - @Session() session: { data?: SessionData }, - @Query("report") reportIndex - ) { + async adminPage(@Session() session: { data?: SessionData }, @Query('report') reportIndex) { let isAdmin = false; - if ( - session.data && - session.data.activeAccount && - session.data.activeAccount.client_roles - ) { + if (session.data && session.data.activeAccount && session.data.activeAccount.client_roles) { for (let role of session.data.activeAccount.client_roles) { - if (role == "ticdi_admin") { + if (role == 'ticdi_admin') { isAdmin = true; } } } - const displayAdmin = isAdmin ? "Administration" : "-"; + const displayAdmin = isAdmin ? 'Administration' : '-'; const title = - process.env.ticdi_environment == "DEVELOPMENT" - ? "DEVELOPMENT - " + PAGE_TITLES.MANAGE_TEMPLATES + process.env.ticdi_environment == 'DEVELOPMENT' + ? 'DEVELOPMENT - ' + PAGE_TITLES.MANAGE_TEMPLATES : PAGE_TITLES.MANAGE_TEMPLATES; let variantJsonArray = []; if (reportIndex == 2) { @@ -289,47 +226,37 @@ export class AppController { } return { title: title, - idirUsername: session.data.activeAccount - ? session.data.activeAccount.idir_username - : "", - primaryContactName: "", + idirUsername: session.data.activeAccount ? session.data.activeAccount.idir_username : '', + primaryContactName: '', displayAdmin: displayAdmin, variantJsonArray: variantJsonArray, }; } - @Get("search") - @Render("search") + @Get('search') + @Render('search') @UseFilters(AuthenticationFilter) @UseGuards(AuthenticationGuard) async searchPage(@Session() session: { data?: SessionData }) { let isAdmin = false; - if ( - session.data && - session.data.activeAccount && - session.data.activeAccount.client_roles - ) { + if (session.data && session.data.activeAccount && session.data.activeAccount.client_roles) { for (let role of session.data.activeAccount.client_roles) { - if (role == "ticdi_admin") { + if (role == 'ticdi_admin') { isAdmin = true; } } } - const displayAdmin = isAdmin ? "Administration" : "-"; + const displayAdmin = isAdmin ? 'Administration' : '-'; const title = - process.env.ticdi_environment == "DEVELOPMENT" - ? "DEVELOPMENT - " + PAGE_TITLES.SEARCH - : PAGE_TITLES.SEARCH; + process.env.ticdi_environment == 'DEVELOPMENT' ? 'DEVELOPMENT - ' + PAGE_TITLES.SEARCH : PAGE_TITLES.SEARCH; return { title: title, - idirUsername: session.data.activeAccount - ? session.data.activeAccount.idir_username - : "", + idirUsername: session.data.activeAccount ? session.data.activeAccount.idir_username : '', displayAdmin: displayAdmin, }; } - @Get("getHello") + @Get('getHello') getHello(): string { return this.appService.getHello(); } @@ -339,83 +266,71 @@ export class AppController { return this.appService.getHello(); } - @Get("/nfr/dtid/:dtid") - @Render("nfr") + @Get('/nfr/dtid/:dtid') + @Render('nfr') @UseFilters(AuthenticationFilter) @UseGuards(AuthenticationGuard) - redirectNFR(@Res() res: Response, @Param("dtid") dtid: number) { + redirectNFR(@Res() res: Response, @Param('dtid') dtid: number) { res.redirect(`/nfr/dtid/${dtid}/${encodeURI(NFR_VARIANTS.default)}`); return {}; } - @Get("/404") - @Render("404") + @Get('/404') + @Render('404') @UseFilters(AuthenticationFilter) @UseGuards(AuthenticationGuard) notFound(@Session() session: { data?: SessionData }) { let isAdmin = false; - if ( - session.data && - session.data.activeAccount && - session.data.activeAccount.client_roles - ) { + if (session.data && session.data.activeAccount && session.data.activeAccount.client_roles) { for (let role of session.data.activeAccount.client_roles) { - if (role == "ticdi_admin") { + if (role == 'ticdi_admin') { isAdmin = true; } } } - const displayAdmin = isAdmin ? "Administration" : "-"; + const displayAdmin = isAdmin ? 'Administration' : '-'; return { - title: "404 Not Found", - message: "Sorry, that page does not exist.", + title: '404 Not Found', + message: 'Sorry, that page does not exist.', displayAdmin: displayAdmin, }; } // grabs Grazing Lease display data and displays the grazing lease report page async getGrazingLeaseDisplayData(session, dtid, res) { - console.log("grazing lease"); + console.log('grazing lease'); let isAdmin = false; - if ( - session.data && - session.data.activeAccount && - session.data.activeAccount.client_roles - ) { + if (session.data && session.data.activeAccount && session.data.activeAccount.client_roles) { for (let role of session.data.activeAccount.client_roles) { - if (role == "ticdi_admin") { + if (role == 'ticdi_admin') { isAdmin = true; } } } const title = - process.env.ticdi_environment == "DEVELOPMENT" - ? "DEVELOPMENT - " + PAGE_TITLES.GRAZING_LEASE + process.env.ticdi_environment == 'DEVELOPMENT' + ? 'DEVELOPMENT - ' + PAGE_TITLES.GRAZING_LEASE : PAGE_TITLES.GRAZING_LEASE; - const displayAdmin = isAdmin ? "Administration" : "-"; + const displayAdmin = isAdmin ? 'Administration' : '-'; await this.ttlsService.setWebadeToken(); let ttlsJSON, primaryContactName; try { - const response: any = await firstValueFrom( - this.ttlsService.callHttp(dtid) - ) + const response: any = await firstValueFrom(this.ttlsService.callHttp(dtid)) .then((res) => { return res; }) .catch((err) => { - console.log("callHttp failed"); + console.log('callHttp failed'); console.log(err); console.log(err.response.data); }); ttlsJSON = await this.ttlsService.formatNFRData(response); primaryContactName = ttlsJSON.licenceHolderName; const interestedParties = nfrInterestedParties(response.tenantAddr); - ttlsJSON["interestedParties"] = interestedParties; - return res.render("grazing-lease", { + ttlsJSON['interestedParties'] = interestedParties; + return res.render('grazing-lease', { title: title, - idirUsername: session.data.activeAccount - ? session.data.activeAccount.idir_username - : "", + idirUsername: session.data.activeAccount ? session.data.activeAccount.idir_username : '', primaryContactName: primaryContactName, displayAdmin: displayAdmin, message: ttlsJSON, @@ -423,11 +338,9 @@ export class AppController { }); } catch (err) { console.log(err); - return res.render("grazing-lease", { + return res.render('grazing-lease', { title: title, - idirUsername: session.data.activeAccount - ? session.data.activeAccount.idir_username - : "", + idirUsername: session.data.activeAccount ? session.data.activeAccount.idir_username : '', primaryContactName: primaryContactName ? primaryContactName : null, displayAdmin: displayAdmin, message: ttlsJSON ? ttlsJSON : null, @@ -441,39 +354,24 @@ export class AppController { async getNfrDisplayData(session, dtid, variantName, res) { let ttlsJSON, primaryContactName, nfrData; let isAdmin = false; - if ( - session.data && - session.data.activeAccount && - session.data.activeAccount.client_roles - ) { + if (session.data && session.data.activeAccount && session.data.activeAccount.client_roles) { for (let role of session.data.activeAccount.client_roles) { - if (role == "ticdi_admin") { + 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" - ); + 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 - ); + const nfrDataObject = await this.reportService.getActiveNfrDataByDtid(dtid); nfrData = nfrDataObject.nfrData; - const provisionIds = nfrDataObject.provisionIds - ? nfrDataObject.provisionIds - : []; - const mandatoryProvisionIds = - await this.reportService.getMandatoryProvisionsByVariant(variantName); + 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) - ) + const response: any = await firstValueFrom(this.ttlsService.callHttp(dtid)) .then((res) => { return res; }) @@ -483,7 +381,7 @@ export class AppController { ttlsJSON = await this.ttlsService.formatNFRData(response); primaryContactName = ttlsJSON.licenceHolderName; const interestedParties = nfrInterestedParties(response.tenantAddr); - ttlsJSON["interestedParties"] = interestedParties; + ttlsJSON['interestedParties'] = interestedParties; let selectedVariant = 0; switch (variantName.toLowerCase()) { case NFR_VARIANTS.default.toLowerCase(): { @@ -507,11 +405,9 @@ export class AppController { break; } } - return res.render("nfr", { + return res.render('nfr', { title: title, - idirUsername: session.data.activeAccount - ? session.data.activeAccount.idir_username - : "", + idirUsername: session.data.activeAccount ? session.data.activeAccount.idir_username : '', primaryContactName: primaryContactName, displayAdmin: displayAdmin, message: ttlsJSON, @@ -524,11 +420,9 @@ export class AppController { }); } catch (err) { console.log(err); - return res.render("nfr", { + return res.render('nfr', { title: title, - idirUsername: session.data.activeAccount - ? session.data.activeAccount.idir_username - : "", + idirUsername: session.data.activeAccount ? session.data.activeAccount.idir_username : '', primaryContactName: primaryContactName ? primaryContactName : null, displayAdmin: displayAdmin, message: ttlsJSON ? ttlsJSON : null,