forked from thisisme-dev/PDFGeneration-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
71 lines (66 loc) · 2.84 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const constants = require('./app/constants');
const logic = require('./app/logic');
const helpers = require('./app/pdf-helpers');
const dateTime = require('node-datetime');
const PDFLimiter = require('./app/pdf-limitations').PDFLimiter;
const pdfLimiter = new PDFLimiter();
module.exports = {
constants,
pdfLimiter: pdfLimiter,
textValueObj: logic.textValueObj,
PDFHelpers: helpers.PDFHelpers,
getPDFContentTemplate: logic.getPDFContentTemplate,
generateReportData: (disclaimer, s3BucketName, reportName, localDebug, debug) => {
const dt = dateTime.create();
const data = {
metaData: {
formatted: dt.format('Y-m-d'),
disclaimer: disclaimer,
s3BucketName: s3BucketName,
reportName: reportName,
LOCAL_DEBUG: localDebug,
DEBUG: debug,
},
requestTimestamp: dt.format('Y-m-d H:M:S'),
};
dt.offsetInDays(3);
data.expiryDate = `${dt.format('w, d n Y H:M:S')} UTC`;
if (debug) {
console.log(data);
}
return data;
},
generateNoResultsPDFContent: logic.generateNoResultsPDFContent,
generateReport: async (reportContent, reportMeta) => {
const requestID = reportContent.requestId;
const pageSetup = logic.setupPDFType(reportContent.pdfType);
const pageOfContents = pageSetup.pageOfContents;
let docY = logic.createPDFDocument(requestID, reportMeta.reportName, pageOfContents, pageSetup.hasCover);
if (pageSetup.hasCover) {
docY = await logic.addCoverPage(docY, reportContent['coverDetails']);
if (pageOfContents !== null) {
docY.doc.addPage(); // create blank page for page of contents
}
} else {
docY = await logic.defaultTop(docY, reportContent);
if (pageOfContents !== null) {
docY.doc.addPage(); // create blank page for page of contents
}
if (pageSetup.addBasicResponseHeader && !pageSetup.hasCover) {
docY = await logic.addDefaultLine(docY, 'Service Response:', null);
}
}
docY = await logic.addPageDetail(docY, reportContent['dataFound'], reportContent.newPageHeaders, pageOfContents, pageSetup.hasCover);
docY.doc = await logic.addPageFooter(docY, requestID, reportMeta.disclaimer);
return await logic.finalizePDFDocument(docY.doc, requestID, reportMeta, pageOfContents, pageSetup.hasCover);
},
generateNoResultsReport: async (reportContent, reportMeta) => {
const requestID = reportContent.requestId;
const pageSetup = logic.setupPDFType(reportContent.pdfType);
const pageOfContents = null;
let docY = logic.createPDFDocument(requestID, reportMeta.reportName, pageOfContents, pageSetup.hasCover);
docY = await logic.defaultTop(docY, reportContent);
docY.doc = await logic.addPageFooter(docY, requestID, reportMeta.disclaimer);
return await logic.finalizePDFDocument(docY.doc, requestID, reportMeta, pageOfContents, pageSetup.hasCover);
},
};