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 ba7cedd187
2 changed files with 11 additions and 6 deletions

View File

@ -1,6 +1,7 @@
import fs from "fs"; import fs from "fs";
import path from 'path'; import path from 'path';
import puppeteer from "puppeteer"; import puppeteer from "puppeteer";
import { Runner } from './models/Runner';
/** /**
* This class is responsible for all things pdf creation. * This class is responsible for all things pdf creation.
@ -17,9 +18,13 @@ export class PdfCreator {
} }
//TODO: Accept the runner class //TODO: Accept the runner class
public async generateSponsoringContract(): Promise<any> { public async generateSponsoringContract(runner: Runner): Promise<any> {
let template = fs.readFileSync(`${this.templateDir}/sponsoring_contract.html`, 'utf8'); 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 }); return await this.renderPdf(template, { format: "A5", landscape: true });
} }

View File

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