From 27a91d9242e80d1055088bed2adf91bb0d20278d Mon Sep 17 00:00:00 2001 From: Pablo Date: Fri, 29 Apr 2022 12:12:16 +0200 Subject: [PATCH] Using path.join --- restapi/{utils => }/InvoiceGenerator.ts | 5 ++++- restapi/utils/PDFHelper.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) rename restapi/{utils => }/InvoiceGenerator.ts (97%) diff --git a/restapi/utils/InvoiceGenerator.ts b/restapi/InvoiceGenerator.ts similarity index 97% rename from restapi/utils/InvoiceGenerator.ts rename to restapi/InvoiceGenerator.ts index 9c63215..097a9c6 100644 --- a/restapi/utils/InvoiceGenerator.ts +++ b/restapi/InvoiceGenerator.ts @@ -1,5 +1,6 @@ const PDFGenerator = require("pdfkit"); const fs = require("fs"); +const path = require("path"); class InvoiceGenerator { invoice: any; @@ -189,7 +190,9 @@ class InvoiceGenerator { const fileName = this.invoice.invoiceNumber + ".pdf"; // pipe to a writable stream which would save the result into the same directory - theOutput.pipe(fs.createWriteStream("./public/pdf/" + fileName)); + theOutput.pipe( + fs.createWriteStream(path.join(__dirname, "public", "pdf", fileName)) + ); this.generateHeaders(theOutput); diff --git a/restapi/utils/PDFHelper.ts b/restapi/utils/PDFHelper.ts index 715301c..cf7ed19 100644 --- a/restapi/utils/PDFHelper.ts +++ b/restapi/utils/PDFHelper.ts @@ -6,7 +6,7 @@ const PDFGenerator = require("pdfkit"); export const createPDF = async (code: string) => { if (process.env.MONGO_DB_URI === undefined) return; - const InvoiceGenerator = require("./InvoiceGenerator"); + const InvoiceGenerator = require("../InvoiceGenerator"); const orderFound = await orderModel.findOne({ code: code,