Now manually parsing runnergroup full names

ref #18
This commit is contained in:
Nicolai Ort 2021-02-17 18:57:21 +01:00
parent 92c52401b3
commit c2909082a2
3 changed files with 40 additions and 2 deletions

View File

@ -18,7 +18,7 @@ export class PdfController {
@Post('/contracts')
@OpenAPI({ description: "Generate Sponsoring contract pdfs from runner objects.<br>You can choose your prefered locale by passing the 'locale' query-param.<br> If you provide more than 100 runenrs this could take a moment or two (we tested up to 1000 runners in about 70sec so far)." })
async generateContracts(@Body({ validate: true, options: { limit: "500mb" } }) runners: Runner | Runner[], @Res() res: any, @QueryParam("locale") locale: string, @QueryParam("codeformat") codeformat: string) {
async generateContracts(@Body({ validate: true, options: { limit: "500mb" } }) runners: Runner[], @Res() res: any, @QueryParam("locale") locale: string, @QueryParam("codeformat") codeformat: string) {
if (!this.initialized) {
await this.pdf.init();
this.initialized = true;
@ -26,6 +26,7 @@ export class PdfController {
if (!Array.isArray(runners)) {
runners = [runners];
}
runners = this.mapRunnerGroupNames(runners)
const contracts = await this.pdf.generateSponsoringContract(runners, locale, codeformat);
res.setHeader('content-type', 'application/pdf');
return contracts;
@ -41,8 +42,37 @@ export class PdfController {
if (!Array.isArray(cards)) {
cards = [cards];
}
cards = this.mapCardGroupNames(cards);
const contracts = await this.pdf.generateRunnerCards(cards, locale);
res.setHeader('content-type', 'application/pdf');
return contracts;
}
private mapRunnerGroupNames(runners: Runner[]): Runner[] {
let response = new Array<Runner>();
for (let runner of runners) {
if (!runner.group.parentGroup) {
runner.group.fullName = runner.group.name;
}
else {
runner.group.fullName = `${runner.group.parentGroup.name}/${runner.group.name}`;
}
response.push(runner)
}
return response;
}
private mapCardGroupNames(cards: RunnerCard[]): RunnerCard[] {
let response = new Array<RunnerCard>();
for (let card of cards) {
if (!card.runner.group.parentGroup) {
card.runner.group.fullName = card.runner.group.name;
}
else {
card.runner.group.fullName = `${card.runner.group.parentGroup.name}/${card.runner.group.name}`;
}
response.push(card)
}
return response;
}
}

View File

@ -13,7 +13,8 @@ import {
IsPositive,
IsString
IsString,
ValidateNested
} from "class-validator";
import { RunnerGroup } from './RunnerGroup';
@ -53,6 +54,7 @@ export class Runner {
* The runner's group.
*/
@IsObject()
@ValidateNested()
group: RunnerGroup;
/**
@ -60,4 +62,8 @@ export class Runner {
*/
@IsInt()
distance: number;
constructor() {
console.log("called")
}
}

View File

@ -25,4 +25,6 @@ export class RunnerGroup {
@IsObject()
@IsOptional()
parentGroup?: RunnerGroup;
fullName: string;
}