PDF Creator now accepts single instances of class

ref #5
This commit is contained in:
Nicolai Ort 2021-02-05 14:09:20 +01:00
parent 041c0ed6bb
commit 78205ee8c7
2 changed files with 12 additions and 6 deletions

View File

@ -1,6 +1,7 @@
import fs from "fs";
import path from 'path';
import puppeteer from "puppeteer";
import { Runner } from './models/Runner';
/**
* This class is responsible for all things pdf creation.
@ -17,9 +18,14 @@ export class PdfCreator {
}
//TODO: Accept the runner class
public async generateSponsoringContract(): Promise<any> {
public async generateSponsoringContract(runner: Runner): Promise<any> {
console.log("runner")
let template = fs.readFileSync(`${this.templateDir}/sponsoring_contract.html`, 'utf8');
template = template.replace("{{Runner Name}}", "lelele");
template = template
.replace("{{runner_id}}", runner.id.toString())
.replace("{{runner_firstname}}", runner.firstname)
.replace("{{runner_lastname}}", runner.lastname)
.replace("{{runner_groupname}}", runner.group.id.toString());
return await this.renderPdf(template, { format: "A5", landscape: true });
}

View File

@ -16,10 +16,10 @@
</head>
<body>
<div class="page">
<h1>{{runner_id}}</h1>
<h1>{{runner_firstname}}</h1>
<h1>{{runner_lastname}}</h1>
<h1>{{runner_groupname}}</h1>
<h1>ID: {{runner_id}}</h1>
<h1>FIRSTNAME: {{runner_firstname}}</h1>
<h1>LASTNAME: {{runner_lastname}}</h1>
<h1>GROUP: {{runner_groupname}}</h1>
</div>
</body>
</html>