parent
05e471878f
commit
119102aef8
@ -14,6 +14,10 @@ export class PdfCreator {
|
|||||||
private templateDir = path.join(__dirname, '/templates');
|
private templateDir = path.join(__dirname, '/templates');
|
||||||
private browser;
|
private browser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main constructor.
|
||||||
|
* Initializes i18n(ext), Handlebars and puppeteer.
|
||||||
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
i18next
|
i18next
|
||||||
.use(Backend)
|
.use(Backend)
|
||||||
@ -34,6 +38,11 @@ export class PdfCreator {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate sponsoring contract pdfs.
|
||||||
|
* @param runner The runner you want to generate the contracts for.
|
||||||
|
* @param locale The locale used for the contracts (default:en)
|
||||||
|
*/
|
||||||
public async generateSponsoringContract(runner: Runner, locale: string = "en"): Promise<any> {
|
public async generateSponsoringContract(runner: Runner, locale: string = "en"): Promise<any> {
|
||||||
i18next.changeLanguage(locale);
|
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');
|
||||||
|
@ -13,6 +13,7 @@ export class PdfController {
|
|||||||
@Post('/contracts')
|
@Post('/contracts')
|
||||||
@OpenAPI({ description: "Generate Sponsoring contract pdfs from runner objects." })
|
@OpenAPI({ description: "Generate Sponsoring contract pdfs from runner objects." })
|
||||||
async generateContracts(@Body({ validate: true }) runner: Runner, @Res() res: any, @QueryParam("locale") locale: string) {
|
async generateContracts(@Body({ validate: true }) runner: Runner, @Res() res: any, @QueryParam("locale") locale: string) {
|
||||||
|
await this.pdf;
|
||||||
const contracts = await this.pdf.generateSponsoringContract(runner, locale);
|
const contracts = await this.pdf.generateSponsoringContract(runner, locale);
|
||||||
res.setHeader('content-type', 'application/pdf');
|
res.setHeader('content-type', 'application/pdf');
|
||||||
return await contracts;
|
return await contracts;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user