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_id}}", runner.id.toString())
.replace("{{runner_firstname}}", runner.firstname) .replace("{{runner_firstname}}", runner.firstname)
.replace("{{runner_lastname}}", runner.lastname) .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 }); 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 { OpenAPI } from 'routing-controllers-openapi';
import { Runner } from '../models/Runner';
import { PdfCreator } from '../PdfCreator'; import { PdfCreator } from '../PdfCreator';
@JsonController() @JsonController()
@ -9,9 +10,10 @@ export class PdfController {
this.pdf = new PdfCreator(); this.pdf = new PdfCreator();
} }
@Get('/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: any, @Res() res: any) { async generateContracts(@Body({ validate: true }) runner: Runner, @Res() res: any) {
console.log(runner)
const contracts = await this.pdf.generateSponsoringContract(runner); const contracts = await this.pdf.generateSponsoringContract(runner);
res.setHeader('content-type', 'application/pdf'); res.setHeader('content-type', 'application/pdf');
return await contracts; return await contracts;

View File

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