From 2e804bd881da61ad3de6f8327d03a2bb12bb4d24 Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Wed, 1 May 2024 11:11:20 -0700 Subject: [PATCH] update DB_ template vars, add types --- backend/src/report/report.service.ts | 45 +++++++++-------- backend/src/ttls/ttls.service.ts | 3 +- backend/src/types.ts | 73 ++++++++++++++++++++++++++++ backend/src/util.ts | 42 ++++++++-------- 4 files changed, 122 insertions(+), 41 deletions(-) diff --git a/backend/src/report/report.service.ts b/backend/src/report/report.service.ts index f17d3022..7ca93b61 100644 --- a/backend/src/report/report.service.ts +++ b/backend/src/report/report.service.ts @@ -4,8 +4,8 @@ import { firstValueFrom } from 'rxjs'; import { DocumentTemplateService } from 'src/document_template/document_template.service'; import { ProvisionService } from 'src/provision/provision.service'; import { TTLSService } from 'src/ttls/ttls.service'; -import { GL_REPORT_TYPE, LUR_REPORT_TYPE, SL_REPORT_TYPE, numberWords, sectionTitles } from '../constants'; -import { ProvisionJSON, VariableJSON } from '../types'; +import { numberWords, sectionTitles } from '../constants'; +import { DTR, ProvisionJSON, VariableJSON } from '../types'; import { convertToSpecialCamelCase, formatMoney, @@ -22,8 +22,7 @@ import { import { DocumentDataService } from 'src/document_data/document_data.service'; import { DocumentDataLogService } from 'src/document_data_log/document_data_log.service'; import { DocumentTypeService } from 'src/document_type/document_type.service'; -import { Provision } from 'src/provision/entities/provision.entity'; -import { DocumentTypeProvision } from 'src/provision/entities/document_type_provision'; + const axios = require('axios'); // generate report needs to be consolidated which is impossible until we figure out how provisions & variables will be dynamically inserted into the docx files @@ -131,9 +130,10 @@ export class ReportService { async generateLURReport(dtid: number, username: string, document_type_id: number) { // get the view given the print request detail id await this.ttlsService.setWebadeToken(); - const rawData: any = await firstValueFrom(this.ttlsService.callHttp(dtid)) + let rawData: DTR; + await firstValueFrom(this.ttlsService.callHttp(dtid)) .then((res) => { - return res; + rawData = res; }) .catch((err) => { console.log(err); @@ -281,9 +281,10 @@ export class ReportService { async generateGLReport(dtid: number, username: string, document_type_id: number) { // get raw ttls data for later await this.ttlsService.setWebadeToken(); - const rawData: any = await firstValueFrom(this.ttlsService.callHttp(dtid)) + let rawData: DTR; + await firstValueFrom(this.ttlsService.callHttp(dtid)) .then((res) => { - return res; + rawData = res; }) .catch((err) => { console.log(err); @@ -374,9 +375,10 @@ export class ReportService { ) { // get raw ttls data for later await this.ttlsService.setWebadeToken(); - const rawData: any = await firstValueFrom(this.ttlsService.callHttp(dtid)) + let rawData: DTR; + await firstValueFrom(this.ttlsService.callHttp(dtid)) .then((res) => { - return res; + rawData = res; }) .catch((err) => { console.log(err); @@ -468,9 +470,10 @@ export class ReportService { ) { // get raw ttls data for later await this.ttlsService.setWebadeToken(); - const rawData: any = await firstValueFrom(this.ttlsService.callHttp(dtid)) + let rawData: DTR; + await firstValueFrom(this.ttlsService.callHttp(dtid)) .then((res) => { - return res; + rawData = res; }) .catch((err) => { console.log(err); @@ -854,9 +857,10 @@ export class ReportService { ) { // get raw ttls data for later await this.ttlsService.setWebadeToken(); - const rawData: any = await firstValueFrom(this.ttlsService.callHttp(dtid)) + let rawData: DTR; + await firstValueFrom(this.ttlsService.callHttp(dtid)) .then((res) => { - return res; + rawData = res; }) .catch((err) => { console.log(err); @@ -995,9 +999,10 @@ export class ReportService { ) { // get raw ttls data for later await this.ttlsService.setWebadeToken(); - const rawData: any = await firstValueFrom(this.ttlsService.callHttp(dtid)) + let rawData: DTR; + await firstValueFrom(this.ttlsService.callHttp(dtid)) .then((res) => { - return res; + rawData = res; }) .catch((err) => { console.log(err); @@ -1040,9 +1045,11 @@ export class ReportService { DB_ADDRESS_STREET_TENANT: glStreetAddress, DB_DOCUMENT_NUMBER: dtid, DB_DOCUMENT_TYPE: documentType.name, - DB_FILE_NUMBER: rawData.fileNum, - DB_TENURE_TYPE: '', - DB_REG_DOCUMENT_NUMBER: 0, + DB_FILE_NUMBER: rawData ? rawData.fileNum : null, + DB_TENURE_TYPE: rawData.type + ? rawData.type.toLowerCase().charAt(0).toUpperCase() + rawData.type.toLowerCase().slice(1) + : '', + DB_REG_DOCUMENT_NUMBER: rawData ? rawData.documentNum : null, }; // parse out the rawData, variableJson, and provisionJson into something useable // combine the formatted TTLS data, variables, and provision sections const data = Object.assign({}, ttlsData, variables); diff --git a/backend/src/ttls/ttls.service.ts b/backend/src/ttls/ttls.service.ts index 95635a5f..0fa06459 100644 --- a/backend/src/ttls/ttls.service.ts +++ b/backend/src/ttls/ttls.service.ts @@ -7,6 +7,7 @@ import { URLSearchParams } from 'url'; import * as dotenv from 'dotenv'; import * as base64 from 'base-64'; import { formatPostalCode, getNFRMailingAddress } from 'src/util'; +import { DTR } from 'src/types'; declare const Buffer; const axios = require('axios'); @@ -272,7 +273,7 @@ export class TTLSService { } } - callHttp(id: number): Observable> { + callHttp(id: number): Observable { const bearerToken = this.webade_token; const url = process.env.ttls_url + id; return this.http.get(url, { headers: { Authorization: 'Bearer ' + bearerToken } }).pipe( diff --git a/backend/src/types.ts b/backend/src/types.ts index 1a9f15c8..e5f7c8b9 100644 --- a/backend/src/types.ts +++ b/backend/src/types.ts @@ -131,3 +131,76 @@ export type IdirObject = { family_name: string; email: string; }; + +export interface DTR { + dtid: number | null; + fileNum: string | null; + orgUnit: string | null; + complexLevel: string | null; + purpose: string | null; + subPurpose: string | null; + subType: string | null; + type: string | null; + bcgsSheet: string | null; + airPhotoNum: string | null; + locLand: string | null; + inspectionDate: string | null; + contactCompanyName: string | null; + contactFirstName: string | null; + contactMiddleName: string | null; + contactLastName: string | null; + contactPhoneNumber: string | null; + contactEmail: string | null; + feePayableType: string | null; + feePayableAmount: number | null; + feePayableAmountGst: number | null; + regOfficeStreet: string | null; + regOfficeCity: string | null; + regOfficeProv: string | null; + regOfficePostalCode: string | null; + gstRate: number | null; + gstExempt: string | null; + gstExemptArea: number | null; + documentNum: number | null; + interestParcel: InterestParcel[]; + tenantAddr: TenantAddressResource[]; +} + +export interface InterestParcel { + interestParcelId: number | null; + legalDescription: string | null; + areaCalcCode: string | null; + areaCalcDescription: string | null; + areaInHectares: number | null; + expiryDate: Date | null; + featureCode: string | null; + areaInSquareMetres: number | null; + areaLengthInMetres: number | null; + wktGeometry: string | null; +} + +export interface TenantAddressResource { + firstName: string | null; + middleName: string | null; + lastName: string | null; + legalName: string | null; + incorporationNum: number | null; + emailAddress: string | null; + locationSid: number | null; + ipSid: number | null; + addrSid: number | null; + addrLine1: string | null; + postalCode: string | null; + city: string | null; + zipCode: string | null; + addrLine2: string | null; + addrLine3: string | null; + countryCd: string | null; + regionCd: string | null; + country: string | null; + provAbbr: string | null; + stateAbbr: string | null; + addrType: string | null; + areaCode: string | null; + phoneNumber: string | null; +} diff --git a/backend/src/util.ts b/backend/src/util.ts index 50097fcc..dec3cf06 100644 --- a/backend/src/util.ts +++ b/backend/src/util.ts @@ -1,3 +1,5 @@ +import { InterestParcel, TenantAddressResource } from './types'; + export function formatMoney(value: number): string { return value.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'); } @@ -212,27 +214,25 @@ export function glAddressBuilder( } export function grazingLeaseVariables( - tenantAddr: [ - { - addrLine1: string; - addrLine2: string; - addrLine3: string; - addrType: string; - firstName: string; - middleName: string; - lastName: string; - legalName: string; - city: string; - country: string; - provAbbr: string; - postalCode: string; - } - ], - interestParcel: [ - { - legalDescription: string; - } - ], + tenantAddr: TenantAddressResource[], + // { + // addrLine1: string; + // addrLine2: string; + // addrLine3: string; + // addrType: string; + // firstName: string; + // middleName: string; + // lastName: string; + // legalName: string; + // city: string; + // country: string; + // provAbbr: string; + // postalCode: string; + // } + interestParcel: InterestParcel[], + // { + // legalDescription: string; + // } regVars: { regOfficeStreet: string; regOfficeCity: string; regOfficeProv: string; regOfficePostalCode: string } ): { streetAddress: string;