Skip to content

Commit

Permalink
fix: pdf generation abs path
Browse files Browse the repository at this point in the history
  • Loading branch information
Suman373 committed Jul 2, 2024
1 parent 6209ccb commit 7ffd4dc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions server/helpers/donationInvoice.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// ------ generate the invoice and send to user email

const path = require("path");
const sendMail = require("../services/email");
const generatePDF = require("../services/generatePDF");
const fs = require('fs');
Expand All @@ -8,14 +9,19 @@ const fs = require('fs');
const donationInvoice = async(pdfData, templateType, cust_email) => {
try {
const pdfName = await generatePDF(pdfData, templateType);
if(!pdfName) throw new Error("PDF generation failed, could not send receipt");
if(!pdfName) throw new Error("PDF generation failed, could not send invoice");
// abs path for invoice
const pdfPath = path.join(__dirname,'..','services','outputs',pdfName);
if (!fs.existsSync(pdfPath)) {
throw new Error(`PDF file ${pdfName} does not exist at path ${pdfPath}`);
}
const emailPayload = {
recipient: `${cust_email}`,
subject: "Blossom: Thank you for your Generous Donation",
text: "Thank you for your generous donation ❤️. Your support is greatly appreciated and will make a significant impact.\n\nPlease find your donation receipt attached to this email.Thank you once again for your kindness and support.\n\nBest regards, Blossom\n https://blossom-web-v1.vercel.app",
attachments: [{
filename: `${pdfName}`,
path: `./services/outputs/${pdfName}`,
path: pdfPath,
contentType: 'application/pdf'
}]
}
Expand All @@ -24,7 +30,7 @@ const donationInvoice = async(pdfData, templateType, cust_email) => {

// clear outputs dir
setTimeout(() => {
fs.unlinkSync(`./services/outputs/${pdfName}`);
fs.unlinkSync(pdfPath);
}, 8000);

} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "server",
"version": "1.5.3",
"version": "1.5.4",
"description": "Server of Blossom",
"main": "server.js",
"scripts": {
Expand Down

0 comments on commit 7ffd4dc

Please sign in to comment.