diff --git a/src/PdfCreator.ts b/src/PdfCreator.ts index 4ccd919..8e547b2 100644 --- a/src/PdfCreator.ts +++ b/src/PdfCreator.ts @@ -9,19 +9,27 @@ export class PdfCreator { private templateDir = path.join(__dirname, '/templates'); //TODO: Accept the runner class - public async generateSponsoringContract(): Promise { + public async generateSponsoringContract(): Promise { let template = fs.readFileSync(`${this.templateDir}/sponsoring_contract.html`, 'utf8'); template = template.replace("{{Runner Name}}", "lelele"); - return await pdf_converter.create(template, { format: "A5", orientation: "landscape" }); + return new Pdf(await pdf_converter.create(template, { format: "A5", orientation: "landscape" })); + } + +} + +export class Pdf { + content: any; + + constructor(pdf: any) { + this.content = pdf; } /** * Promise wrapper function that resolves the toBuffer promise for pdf generation. - * @param pdf The pdf object that shall be turned into a buffer. */ - public async toBuffer(pdf): Promise { + public async toBuffer(): Promise { let promise = await new Promise((resolve, reject) => { - pdf.toBuffer(function (err, buffer) { + this.content.toBuffer(function (err, buffer) { resolve(buffer); }); }); @@ -30,14 +38,13 @@ export class PdfCreator { /** * Promise wrapper function that resolves the toStream promise for pdf generation. - * @param pdf The pdf object that shall be turned into a stream. */ - public async toStream(pdf): Promise { + public async toStream(): Promise { let promise = await new Promise((resolve, reject) => { - pdf.toStream(function (err, stream) { + this.content.toStream(function (err, stream) { resolve(stream); }); }); return await promise; } -} +} \ No newline at end of file diff --git a/src/controllers/PdfController.ts b/src/controllers/PdfController.ts index 9770b11..0ec9581 100644 --- a/src/controllers/PdfController.ts +++ b/src/controllers/PdfController.ts @@ -15,6 +15,6 @@ export class PdfController { async generateContracts() { //TODO: Accept the real classes const contracts = await this.pdf.generateSponsoringContract(); - return await this.pdf.toBuffer(contracts); + return await contracts.toBuffer(); } } \ No newline at end of file