1- import { isNil , isString } from 'lodash' ;
1+ import { isNil , isString , isUndefined } from 'lodash' ;
22import fs from 'fs' ;
33import { create } from 'handlebars' ;
44import knex from 'knex' ;
@@ -22,9 +22,11 @@ import {
2222 SITE_STATUS_TYPES ,
2323 WEB_LINK_TYPES ,
2424} from '../../models' ;
25+ import { PhotoService } from '../photo-service' ;
2526import BaseService from '../base-service' ;
2627
2728const db = knex ( DB_CONFIG ) ;
29+ const photoService = new PhotoService ( DB_CONFIG ) ;
2830
2931export class PrintSiteService extends BaseService {
3032 constructor (
@@ -54,6 +56,7 @@ export class PrintSiteService extends BaseService {
5456 const template = h . compile ( PDF_TEMPLATE . toString ( ) , { } ) ;
5557
5658 const {
59+ id : placeId ,
5760 primaryName,
5861 names,
5962 historicalPatterns,
@@ -179,6 +182,18 @@ export class PrintSiteService extends BaseService {
179182 secondaryStatuteHandlebarData = await this . makeStatuteHandlebarData ( this . place . statute2Id ) ;
180183 }
181184
185+ let photos : any [ ] = [ ] ;
186+ if ( includePhotosSection && ! isUndefined ( placeId ) ) {
187+ photos = await photoService . getAllForPlace ( placeId ) ;
188+ }
189+ //console.log(photos[0]);
190+ const photosWithDataUris = photos
191+ . filter ( ( photo ) => photo . ThumbFile && Buffer . isBuffer ( photo . ThumbFile ) )
192+ . map ( ( photo ) => ( {
193+ ...photo ,
194+ dataUri : `data:image/jpeg;base64,${ photo . ThumbFile . toString ( 'base64' ) } ` ,
195+ } ) ) ;
196+
182197 const handlebarsData = {
183198 includeSummarySection,
184199 includeLocationSection,
@@ -266,6 +281,7 @@ export class PrintSiteService extends BaseService {
266281 statute : statuteHandlebarData ,
267282 secondaryStatute : secondaryStatuteHandlebarData ,
268283 descriptions : descriptionsHandlebarData ,
284+ photos : photosWithDataUris ,
269285 } ;
270286
271287 return template ( handlebarsData ) ;
0 commit comments