first working pdf generation from class 🎉

ref #5
This commit is contained in:
Nicolai Ort 2021-02-05 17:59:26 +01:00
parent d58453faf9
commit 3af76a53e3
4 changed files with 26 additions and 8 deletions

View File

@ -24,7 +24,7 @@ export class PdfCreator {
.replace("{{runner_id}}", runner.id.toString())
.replace("{{runner_firstname}}", runner.firstname)
.replace("{{runner_lastname}}", runner.lastname)
.replace("{{runner_groupname}}", runner.group.id.toString());
.replace("{{runner_groupname}}", runner.group.name);
return await this.renderPdf(template, { format: "A5", landscape: true });
}

View File

@ -1,5 +1,6 @@
import { Body, Get, JsonController, Res } from 'routing-controllers';
import { Body, JsonController, Post, Res } from 'routing-controllers';
import { OpenAPI } from 'routing-controllers-openapi';
import { Runner } from '../models/Runner';
import { PdfCreator } from '../PdfCreator';
@JsonController()
@ -9,9 +10,10 @@ export class PdfController {
this.pdf = new PdfCreator();
}
@Get('/contracts')
@Post('/contracts')
@OpenAPI({ description: "Generate Sponsoring contract pdfs from runner objects." })
async generateContracts(@Body({ validate: true }) runner: any, @Res() res: any) {
async generateContracts(@Body({ validate: true }) runner: Runner, @Res() res: any) {
console.log(runner)
const contracts = await this.pdf.generateSponsoringContract(runner);
res.setHeader('content-type', 'application/pdf');
return await contracts;

View File

@ -1,6 +1,18 @@
import {
IsInt,
IsNotEmpty,
IsObject,
IsOptional,
IsPositive,
IsString
} from "class-validator";
import { RunnerGroup } from './RunnerGroup';
@ -13,24 +25,28 @@ export class Runner {
* The runner's id.
*/
@IsInt()
@IsPositive()
id: number;
/**
* The runner's first name.
*/
@IsString()
@IsNotEmpty()
firstname: string;
/**
* The runner's middle name.
*/
@IsString()
@IsOptional()
middlename?: string;
/**
* The runner's last name.
*/
@IsString()
@IsNotEmpty()
lastname: string;
/**

View File

@ -1,15 +1,15 @@
import { IsInt, IsNotEmpty, IsObject, IsOptional, IsString } from "class-validator";
import { IsInt, IsNotEmpty, IsObject, IsOptional, IsPositive, IsString } from "class-validator";
/**
* Defines the runner group class - a simplified version of the backend's ResponseRunnerTeam/-Organization
*/
export abstract class RunnerGroup {
export class RunnerGroup {
/**
* The group's id.
*/
@IsInt()
@IsNotEmpty()
id: number;;
@IsPositive()
id: number;
/**
* The group's name.