@@ -43,11 +43,11 @@ export class PdfCreator {
 | 
			
		||||
     * @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(runners: Runner[], locale: string = "en"): Promise<any> {
 | 
			
		||||
        i18next.changeLanguage(locale);
 | 
			
		||||
        const template_source = fs.readFileSync(`${this.templateDir}/sponsoring_contract.html`, 'utf8');
 | 
			
		||||
        const template = Handlebars.compile(template_source);
 | 
			
		||||
        const result = template({ runner: runner })
 | 
			
		||||
        const result = template({ runners })
 | 
			
		||||
        return await this.renderPdf(result, { format: "A5", landscape: true });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -12,9 +12,12 @@ export class PdfController {
 | 
			
		||||
 | 
			
		||||
    @Post('/contracts')
 | 
			
		||||
    @OpenAPI({ description: "Generate Sponsoring contract pdfs from runner objects." })
 | 
			
		||||
    async generateContracts(@Body({ validate: true }) runner: Runner, @Res() res: any, @QueryParam("locale") locale: string) {
 | 
			
		||||
        const contracts = await this.pdf.generateSponsoringContract(runner, locale);
 | 
			
		||||
    async generateContracts(@Body({ validate: true }) runners: Runner | Runner[], @Res() res: any, @QueryParam("locale") locale: string) {
 | 
			
		||||
        if (!Array.isArray(runners)) {
 | 
			
		||||
            runners = [runners]
 | 
			
		||||
        }
 | 
			
		||||
        const contracts = await this.pdf.generateSponsoringContract(runners, locale);
 | 
			
		||||
        res.setHeader('content-type', 'application/pdf');
 | 
			
		||||
        return await contracts;
 | 
			
		||||
        return contracts;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,11 +5,13 @@
 | 
			
		||||
    <link rel="stylesheet" href="https://unpkg.com/mvp.css">
 | 
			
		||||
  </head>
 | 
			
		||||
  <body>
 | 
			
		||||
    {{#each runners}}
 | 
			
		||||
    <div class="page">
 | 
			
		||||
      <p>ID: {{runner.id}}</p>
 | 
			
		||||
      <p>{{__ "firstname"}}: {{runner.firstname}}</p>
 | 
			
		||||
      <p>{{__ "lastname"}}: {{runner.lastname}}</p>
 | 
			
		||||
      <p>{{__ "group"}}: {{runner.group.name}}</p>
 | 
			
		||||
      <p>ID: {{this.id}}</p>
 | 
			
		||||
      <p>{{__ "firstname"}}: {{this.firstname}}</p>
 | 
			
		||||
      <p>{{__ "lastname"}}: {{this.lastname}}</p>
 | 
			
		||||
      <p>{{__ "group"}}: {{this.group.name}}</p>
 | 
			
		||||
    </div>
 | 
			
		||||
  {{/each}}
 | 
			
		||||
  </body>
 | 
			
		||||
</html>
 | 
			
		||||
		Reference in New Issue
	
	Block a user