Skip to content

Commit

Permalink
Merge pull request #189 from bcgov/TICDI-358_update
Browse files Browse the repository at this point in the history
update DB_ template vars, add types
  • Loading branch information
mgtennant authored May 1, 2024
2 parents 1e0ccd3 + 2e804bd commit d140028
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 41 deletions.
45 changes: 26 additions & 19 deletions backend/src/report/report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion backend/src/ttls/ttls.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -272,7 +273,7 @@ export class TTLSService {
}
}

callHttp(id: number): Observable<Array<Object>> {
callHttp(id: number): Observable<DTR> {
const bearerToken = this.webade_token;
const url = process.env.ttls_url + id;
return this.http.get(url, { headers: { Authorization: 'Bearer ' + bearerToken } }).pipe(
Expand Down
73 changes: 73 additions & 0 deletions backend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
42 changes: 21 additions & 21 deletions backend/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { InterestParcel, TenantAddressResource } from './types';

export function formatMoney(value: number): string {
return value.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d140028

Please sign in to comment.