Skip to content

Commit 228d3fb

Browse files
committed
Updates to print site service
1 parent 0647f7e commit 228d3fb

File tree

2 files changed

+264
-18
lines changed

2 files changed

+264
-18
lines changed

api/models/place.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import {
1111
Contact,
1212
Theme,
1313
FunctionalUse,
14+
Ownership,
15+
RevisionLog,
16+
WebLink,
1417
} from '.';
1518
import { Date as DateModel } from '../models/date';
1619

@@ -94,6 +97,10 @@ export class Place {
9497
descriptions?: Description[];
9598
themes?: Theme[];
9699
functionalUses?: FunctionalUse[];
100+
ownerships?: Ownership[];
101+
previousOwnerships?: Ownership[];
102+
revisionLogs?: RevisionLog[];
103+
webLinks?: WebLink[];
97104

98105
static FIELDS: ReadonlyArray<string> = Object.freeze([
99106
'id',

api/services/place/print-site-service.ts

Lines changed: 257 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isNil } from 'lodash';
1+
import { isNil, isString } from 'lodash';
22
import fs from 'fs';
33
import { create } from 'handlebars';
44
import knex from 'knex';
@@ -7,10 +7,20 @@ import { DB_CONFIG } from '../../config';
77

88
import handlebarsHelpers from '../../utils/handlebars-helpers';
99
import {
10+
ASSOCIATION_TYPES,
11+
CONDITION_TYPES,
1012
CONSTRUCTION_PERIOD_TYPES,
13+
CONTACT_TYPES,
1114
DESCRIPTION_TYPES,
15+
FIRST_NATION_ASSOCIATION_TYPES,
1216
FUNCTIONAL_USE_TYPES,
17+
JURISDICTION_TYPES,
18+
OWNER_CONSENT_TYPES,
19+
OWNERSHIP_TYPES,
1320
Place,
21+
REVISION_LOG_TYPES,
22+
SITE_STATUS_TYPES,
23+
WEB_LINK_TYPES,
1424
} from '../../models';
1525
import BaseService from '../base-service';
1626

@@ -48,11 +58,7 @@ export class PrintSiteService extends BaseService {
4858
names,
4959
historicalPatterns,
5060
yHSIId,
51-
jurisdiction,
52-
statuteId,
53-
statute2Id,
5461
recognitionDate,
55-
ownerConsent,
5662
category,
5763
isPubliclyAccessible,
5864
nTSMapSheet,
@@ -109,16 +115,70 @@ export class PrintSiteService extends BaseService {
109115
communityName,
110116
coordinateDeterminationName,
111117
hasPendingChanges,
112-
associations,
113-
contacts,
114118
dates,
119+
previousOwnerships,
115120
} = this.place;
116121

117122
const constructionPeriodsHandlebarData = this.makeConstructionPeriodsHandlebarData();
123+
124+
const foundFloorCondition = CONDITION_TYPES.find(
125+
(conditionType) => conditionType.value == floorCondition
126+
);
127+
const floorConditionName = foundFloorCondition ? foundFloorCondition.text : 'Not Applicable';
128+
129+
const foundRoofCondition = CONDITION_TYPES.find(
130+
(conditionType) => conditionType.value == roofCondition
131+
);
132+
const roofConditionName = foundRoofCondition ? foundRoofCondition.text : 'Not Applicable';
133+
134+
const foundWallCondition = CONDITION_TYPES.find(
135+
(conditionType) => conditionType.value == wallCondition
136+
);
137+
const wallConditionName = foundWallCondition ? foundWallCondition.text : 'Not Applicable';
138+
139+
const foundDoorCondition = CONDITION_TYPES.find(
140+
(conditionType) => conditionType.value == doorCondition
141+
);
142+
const doorConditionName = foundDoorCondition ? foundDoorCondition.text : 'Not Applicable';
143+
144+
const foundSiteStatus = SITE_STATUS_TYPES.find(
145+
(siteStatusType) => siteStatusType.value == siteStatus
146+
);
147+
const siteStatusName = foundSiteStatus ? foundSiteStatus.text : 'Not Applicable';
148+
118149
const themesHandlebarData = await this.makeThemesHandlebarData();
119150
const functionalUsesHandlebarData = await this.makeFunctionalUsesHandlebarData();
151+
const associationsHandlebarData = this.makeAssociationsHandlebarData();
152+
const firstNationAssociationsHandlebarData =
153+
await this.makeFirstNationAssociationsHandlebarData();
154+
const ownershipsHandlebarData = this.makeOwnershipsHandlebarData();
155+
const contactsHandlebarData = this.makeContactsHandlebarData();
156+
const revisionLogsHandlebarData = this.makeRevisionLogsHandlebarData();
157+
const webLinksHandlebarData = this.makeWebLinksHandlebarData();
120158
const descriptionsHandlebarData = this.makeDescriptionsHandlebarData();
121159

160+
const foundJurisdiction = JURISDICTION_TYPES.find(
161+
(jurisdictionType) => jurisdictionType.value == this.place.jurisdiction
162+
);
163+
164+
const jurisdictionHandlebarData = foundJurisdiction ? foundJurisdiction.text : 'None Selected';
165+
166+
const foundOwnerConsent = OWNER_CONSENT_TYPES.find(
167+
(ownerConsentType) => ownerConsentType.value == this.place.ownerConsent
168+
);
169+
170+
const ownerConsentHandlebarData = foundOwnerConsent ? foundOwnerConsent.text : 'None Selected';
171+
172+
let statuteHandlebarData = '';
173+
if (!isNil(this.place.statuteId)) {
174+
statuteHandlebarData = await this.makeStatuteHandlebarData(this.place.statuteId);
175+
}
176+
177+
let secondaryStatuteHandlebarData = '';
178+
if (!isNil(this.place.statute2Id)) {
179+
secondaryStatuteHandlebarData = await this.makeStatuteHandlebarData(this.place.statute2Id);
180+
}
181+
122182
const handlebarsData = {
123183
includeSummarySection,
124184
includeLocationSection,
@@ -133,11 +193,7 @@ export class PrintSiteService extends BaseService {
133193
names,
134194
historicalPatterns,
135195
yHSIId,
136-
jurisdiction,
137-
statuteId,
138-
statute2Id,
139196
recognitionDate,
140-
ownerConsent,
141197
category,
142198
isPubliclyAccessible,
143199
nTSMapSheet,
@@ -172,11 +228,11 @@ export class PrintSiteService extends BaseService {
172228
locationContext,
173229
communityId,
174230
lAGroup,
175-
siteStatus,
176-
floorCondition,
177-
wallCondition,
178-
doorCondition,
179-
roofCondition,
231+
siteStatus: siteStatusName,
232+
floorCondition: floorConditionName,
233+
wallCondition: wallConditionName,
234+
doorCondition: doorConditionName,
235+
roofCondition: roofConditionName,
180236
coordinateDetermination,
181237
physicalAddress,
182238
physicalProvince,
@@ -194,12 +250,21 @@ export class PrintSiteService extends BaseService {
194250
communityName,
195251
coordinateDeterminationName,
196252
hasPendingChanges,
197-
associations,
198253
constructionPeriods: constructionPeriodsHandlebarData,
199-
contacts,
200254
dates,
201255
themes: themesHandlebarData,
202256
functionalUses: functionalUsesHandlebarData,
257+
associations: associationsHandlebarData,
258+
firstNationAssociations: firstNationAssociationsHandlebarData,
259+
ownerships: ownershipsHandlebarData,
260+
previousOwnerships,
261+
revisionLogs: revisionLogsHandlebarData,
262+
contacts: contactsHandlebarData,
263+
webLinks: webLinksHandlebarData,
264+
jurisdiction: jurisdictionHandlebarData,
265+
ownerConsent: ownerConsentHandlebarData,
266+
statute: statuteHandlebarData,
267+
secondaryStatute: secondaryStatuteHandlebarData,
203268
descriptions: descriptionsHandlebarData,
204269
};
205270

@@ -279,6 +344,180 @@ export class PrintSiteService extends BaseService {
279344
return functionalUsesHandlebarData;
280345
}
281346

347+
private makeAssociationsHandlebarData() {
348+
const associationsHandlebarData: { type: string; description: string }[] = [];
349+
if (isNil(this.place.associations)) return [];
350+
351+
for (const association of this.place.associations) {
352+
const a = ASSOCIATION_TYPES.find(
353+
(associationType) => associationType.value == association.type
354+
);
355+
356+
if (isNil(a)) continue;
357+
358+
associationsHandlebarData.push({
359+
type: a.text,
360+
description: association.description,
361+
});
362+
}
363+
364+
return associationsHandlebarData;
365+
}
366+
367+
private async makeFirstNationAssociationsHandlebarData() {
368+
const firstNationAssociationsHandlebarData: {
369+
firstNation: string;
370+
firstNationAssociationType: string;
371+
comments: string;
372+
}[] = [];
373+
if (isNil(this.place.firstNationAssociations)) return [];
374+
375+
for (const firstNationAssociation of this.place.firstNationAssociations) {
376+
const firstNationAssociationType = FIRST_NATION_ASSOCIATION_TYPES.find(
377+
(firstNationAssociationType) =>
378+
firstNationAssociationType.value == firstNationAssociation.firstNationAssociationType
379+
);
380+
381+
if (isNil(firstNationAssociationType)) continue;
382+
383+
const firstNation = await db('FirstNation')
384+
.select('description')
385+
.where({ id: firstNationAssociation.firstNationId })
386+
.then((results) => {
387+
return results[0].description;
388+
});
389+
390+
if (isNil(firstNation)) continue;
391+
392+
firstNationAssociationsHandlebarData.push({
393+
firstNation: firstNation,
394+
firstNationAssociationType: firstNationAssociationType.text,
395+
comments: firstNationAssociation.comments,
396+
});
397+
}
398+
399+
return firstNationAssociationsHandlebarData;
400+
}
401+
402+
private makeOwnershipsHandlebarData() {
403+
const ownershipsHandlebarData: { ownershipType: string; comments: string }[] = [];
404+
if (isNil(this.place.ownerships)) return [];
405+
406+
for (const ownership of this.place.ownerships) {
407+
const ownershipType = OWNERSHIP_TYPES.find(
408+
(ownershipType) => ownershipType.value == ownership.ownershipType
409+
);
410+
411+
if (isNil(ownershipType)) continue;
412+
413+
ownershipsHandlebarData.push({
414+
ownershipType: ownershipType.text,
415+
comments: ownership.comments,
416+
});
417+
}
418+
419+
return ownershipsHandlebarData;
420+
}
421+
422+
private makeRevisionLogsHandlebarData() {
423+
const revisionLogsHandlebarData: {
424+
revisionLogType: string;
425+
revisionDate: string;
426+
revisedBy: string;
427+
details: string;
428+
}[] = [];
429+
430+
if (isNil(this.place.revisionLogs)) return [];
431+
432+
this.place.revisionLogs.forEach((revisionLog) => {
433+
const d = REVISION_LOG_TYPES.find(
434+
(revisionLogType) => revisionLogType.value == revisionLog.revisionLogType
435+
);
436+
437+
if (isNil(d)) return;
438+
439+
revisionLogsHandlebarData.push({
440+
revisionLogType: d.text,
441+
revisionDate: revisionLog.revisionDate,
442+
revisedBy: revisionLog.revisedBy,
443+
details: revisionLog.details,
444+
});
445+
});
446+
447+
return revisionLogsHandlebarData;
448+
}
449+
450+
private makeContactsHandlebarData() {
451+
const contactsHandlebarData: {
452+
contactType: string;
453+
description: string;
454+
email: string;
455+
firstName: string;
456+
lastName: string;
457+
mailingAddress: string;
458+
phoneNumber: string;
459+
}[] = [];
460+
461+
if (isNil(this.place.contacts)) return [];
462+
463+
this.place.contacts.forEach((contact) => {
464+
const d = CONTACT_TYPES.find((contactType) => contactType.value == contact.contactType);
465+
466+
if (isNil(d)) return;
467+
468+
contactsHandlebarData.push({
469+
contactType: d.text,
470+
description: contact.description,
471+
email: contact.email,
472+
firstName: contact.firstName,
473+
lastName: contact.lastName,
474+
mailingAddress: contact.mailingAddress,
475+
phoneNumber: contact.phoneNumber,
476+
});
477+
});
478+
479+
return contactsHandlebarData;
480+
}
481+
482+
private makeWebLinksHandlebarData() {
483+
const webLinksHandlebarData: { type: string; address: string }[] = [];
484+
485+
if (isNil(this.place.webLinks)) return [];
486+
487+
this.place.webLinks.forEach((webLink) => {
488+
const d = WEB_LINK_TYPES.find((webLinkType) => webLinkType.value == webLink.type);
489+
490+
if (isNil(d)) return;
491+
492+
webLinksHandlebarData.push({
493+
type: d.text,
494+
address: webLink.address,
495+
});
496+
});
497+
498+
return webLinksHandlebarData;
499+
}
500+
501+
private async makeStatuteHandlebarData(statuteId: number) {
502+
const statute = await db('Statute')
503+
.select('RecognitionAuthority', 'RecognitionType', 'Description', 'AllStatute')
504+
.where({ Id: statuteId })
505+
.then((results) => {
506+
return results[0];
507+
});
508+
509+
if (isNil(statute)) return '';
510+
511+
const { RecognitionAuthority, RecognitionType, Description, AllStatute } = statute;
512+
513+
if (!isString(RecognitionAuthority)) return '';
514+
if (!isString(RecognitionType)) return '';
515+
if (!isString(Description)) return '';
516+
if (!isString(AllStatute)) return '';
517+
518+
return `${RecognitionAuthority} / ${RecognitionType} / ${Description} / ${AllStatute}`;
519+
}
520+
282521
private makeDescriptionsHandlebarData() {
283522
const descriptions: {
284523
value: string;

0 commit comments

Comments
 (0)