From 3949c3c9aa93bc83b239cd9a594a7d3117790ddd Mon Sep 17 00:00:00 2001 From: Vidyaranya-Gavai-TTPL Date: Wed, 27 Nov 2024 15:05:01 +0530 Subject: [PATCH] Dynamic HTML Done (#14) * Dynamic HTML Done * Delete .vscode/settings.json --------- Co-authored-by: Manoj L --- src/inspector/inspector.service.ts | 41 +++++++++++++++++++- src/main.ts | 5 ++- template/casteCertificate.html | 16 +------- template/sportsParticipationCertificate.html | 16 +------- 4 files changed, 47 insertions(+), 31 deletions(-) diff --git a/src/inspector/inspector.service.ts b/src/inspector/inspector.service.ts index 61881a3..5971973 100644 --- a/src/inspector/inspector.service.ts +++ b/src/inspector/inspector.service.ts @@ -384,11 +384,50 @@ export class InspectorService { async renderHtml(data: any, type: any): Promise { const htmlTemplate = await this.loadTemplate(type); // Load the HTML template from file const template = Handlebars.compile(htmlTemplate); // Compile the template using Handlebars - console.log('-----------------------', htmlTemplate, data); + // console.log('-----------------------', htmlTemplate, data); + + data = this.mapCertificateData(data); return template(data); // Inject the dynamic data } + mapCertificateData(data: any) { + const mappedData: { [key: string]: any } = {}; + const addressFields = [ + 'addressLine1', + 'addressLine2', + 'house', + 'landmark', + 'locality', + 'vtc', + 'district', + 'pin', + 'state', + 'country', + 'orgAddressLine1', + 'orgAddressLine2', + 'orgLandmark', + 'orgLocality', + 'orgVtc', + 'orgDistrict', + 'orgPin', + 'orgState', + 'orgCountry', + 'schoolAddressLine1', + 'schoolAddressLine2', + ]; + + for (const key in data) { + if (data.hasOwnProperty(key)) { + if (addressFields.includes(key)) { + mappedData[key] = data[key] !== null ? data[key] + ', ' : ''; + } else mappedData[key] = data[key] || '--'; + } + } + + return mappedData; + } + async generateQrCode(id: string): Promise { const text = `${this.baseUrl}/credentials/credentials/${id}/verify`; try { diff --git a/src/main.ts b/src/main.ts index 0f72a1b..25f4276 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,9 +9,10 @@ async function bootstrap() { const globalPrefix = process.env.API_PREFIX || 'api'; app.setGlobalPrefix(globalPrefix); + const PORT = process.env.PORT || 3000; console.log( - `Application is running on: http://localhost:${process.env.PORT}/${globalPrefix}`, + `Application is running on: http://localhost:${PORT}/${globalPrefix}`, ); - await app.listen(process.env.PORT); + await app.listen(PORT); } bootstrap(); diff --git a/template/casteCertificate.html b/template/casteCertificate.html index 42ff76d..937c052 100644 --- a/template/casteCertificate.html +++ b/template/casteCertificate.html @@ -164,20 +164,8 @@

Issuing Authority

{{orgOfficerRank}} - District - {{orgDistrict}} - - - PIN - {{orgPin}} - - - State - {{orgState}} - - - Country - {{orgCountry}} + Address + {{orgDistrict}} {{orgPin}} {{orgState}} {{orgCountry}} diff --git a/template/sportsParticipationCertificate.html b/template/sportsParticipationCertificate.html index ed449c1..c48ed17 100644 --- a/template/sportsParticipationCertificate.html +++ b/template/sportsParticipationCertificate.html @@ -185,20 +185,8 @@

Issuing Authority

{{orgOfficerRank}} - District - {{orgDistrict}} - - - PIN - {{orgPin}} - - - State - {{orgState}} - - - Country - {{orgCountry}} + Address + {{orgDistrict}} {{orgPin}} {{orgState}} {{orgCountry}}