parent
5e1252545b
commit
1ced0e3175
@ -8,6 +8,7 @@ import mime from "mime-types";
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import puppeteer from "puppeteer";
|
import puppeteer from "puppeteer";
|
||||||
import { Runner } from './models/Runner';
|
import { Runner } from './models/Runner';
|
||||||
|
import { RunnerGroup } from './models/RunnerGroup';
|
||||||
/**
|
/**
|
||||||
* This class is responsible for all things pdf creation.
|
* This class is responsible for all things pdf creation.
|
||||||
* This uses the html templates from src/templates.
|
* This uses the html templates from src/templates.
|
||||||
@ -53,6 +54,9 @@ export class PdfCreator {
|
|||||||
* @param locale The locale used for the contracts (default:en)
|
* @param locale The locale used for the contracts (default:en)
|
||||||
*/
|
*/
|
||||||
public async generateSponsoringContract(runners: Runner[], locale: string = "en"): Promise<any> {
|
public async generateSponsoringContract(runners: Runner[], locale: string = "en"): Promise<any> {
|
||||||
|
if (runners.length == 1 && Object.keys(runners[0]).length == 0) {
|
||||||
|
runners[0] = this.generateEmptyRunner();
|
||||||
|
}
|
||||||
await i18next.changeLanguage(locale);
|
await i18next.changeLanguage(locale);
|
||||||
const template_source = fs.readFileSync(`${this.templateDir}/sponsoring_contract.html`, 'utf8');
|
const template_source = fs.readFileSync(`${this.templateDir}/sponsoring_contract.html`, 'utf8');
|
||||||
const template = Handlebars.compile(template_source);
|
const template = Handlebars.compile(template_source);
|
||||||
@ -107,4 +111,21 @@ export class PdfCreator {
|
|||||||
await page.close();
|
await page.close();
|
||||||
return pdf;
|
return pdf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a new dummy runner with halfspaces for all strings.
|
||||||
|
* Can be used to generate empty sponsoring contracts.
|
||||||
|
* @returns A new runner object that apears to be empty.
|
||||||
|
*/
|
||||||
|
private generateEmptyRunner(): Runner {
|
||||||
|
let group = new RunnerGroup();
|
||||||
|
group.id = 0;
|
||||||
|
group.name = " ";
|
||||||
|
let runner = new Runner();
|
||||||
|
runner.id = 0;
|
||||||
|
runner.firstname = " ";
|
||||||
|
runner.lastname = " ";
|
||||||
|
runner.group = group;
|
||||||
|
return runner;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user