Merge pull request 'Now using full group names feature/18-group_names' (#30) from feature/18-group_names into dev
continuous-integration/drone/push Build is passing Details

Reviewed-on: #30
This commit is contained in:
Nicolai Ort 2021-02-18 15:16:53 +00:00
commit e0db6f6a78
5 changed files with 42 additions and 4 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;
}

View File

@ -48,7 +48,7 @@
</div>
</div>
<p>{{this.runner.lastname}}, {{this.runner.firstname}} {{this.runner.middlename}}</p>
<p>{{this.runner.group.name}}</p>
<p>{{this.runner.group.fullName}}</p>
</div>
{{/each}}
</div>

View File

@ -64,7 +64,7 @@
<p style="font-size: x-small; display: block;">{{__ "lastname"}}</p>
</div>
<div class="column is-6">
<span style="border-bottom: 1px solid; width: 100%; display: block;">{{this.group.name}}</span>
<span style="border-bottom: 1px solid; width: 100%; display: block;">{{this.group.fullName}}</span>
<p style="font-size: x-small; display: block;">{{__ "group"}}</p>
</div>
</div>