parent
92c52401b3
commit
c2909082a2
@ -18,7 +18,7 @@ export class PdfController {
|
|||||||
|
|
||||||
@Post('/contracts')
|
@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)." })
|
@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) {
|
if (!this.initialized) {
|
||||||
await this.pdf.init();
|
await this.pdf.init();
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
@ -26,6 +26,7 @@ export class PdfController {
|
|||||||
if (!Array.isArray(runners)) {
|
if (!Array.isArray(runners)) {
|
||||||
runners = [runners];
|
runners = [runners];
|
||||||
}
|
}
|
||||||
|
runners = this.mapRunnerGroupNames(runners)
|
||||||
const contracts = await this.pdf.generateSponsoringContract(runners, locale, codeformat);
|
const contracts = await this.pdf.generateSponsoringContract(runners, locale, codeformat);
|
||||||
res.setHeader('content-type', 'application/pdf');
|
res.setHeader('content-type', 'application/pdf');
|
||||||
return contracts;
|
return contracts;
|
||||||
@ -41,8 +42,37 @@ export class PdfController {
|
|||||||
if (!Array.isArray(cards)) {
|
if (!Array.isArray(cards)) {
|
||||||
cards = [cards];
|
cards = [cards];
|
||||||
}
|
}
|
||||||
|
cards = this.mapCardGroupNames(cards);
|
||||||
const contracts = await this.pdf.generateRunnerCards(cards, locale);
|
const contracts = await this.pdf.generateRunnerCards(cards, locale);
|
||||||
res.setHeader('content-type', 'application/pdf');
|
res.setHeader('content-type', 'application/pdf');
|
||||||
return contracts;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,8 @@ import {
|
|||||||
|
|
||||||
IsPositive,
|
IsPositive,
|
||||||
|
|
||||||
IsString
|
IsString,
|
||||||
|
ValidateNested
|
||||||
} from "class-validator";
|
} from "class-validator";
|
||||||
import { RunnerGroup } from './RunnerGroup';
|
import { RunnerGroup } from './RunnerGroup';
|
||||||
|
|
||||||
@ -53,6 +54,7 @@ export class Runner {
|
|||||||
* The runner's group.
|
* The runner's group.
|
||||||
*/
|
*/
|
||||||
@IsObject()
|
@IsObject()
|
||||||
|
@ValidateNested()
|
||||||
group: RunnerGroup;
|
group: RunnerGroup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,4 +62,8 @@ export class Runner {
|
|||||||
*/
|
*/
|
||||||
@IsInt()
|
@IsInt()
|
||||||
distance: number;
|
distance: number;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
console.log("called")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,4 +25,6 @@ export class RunnerGroup {
|
|||||||
@IsObject()
|
@IsObject()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
parentGroup?: RunnerGroup;
|
parentGroup?: RunnerGroup;
|
||||||
|
|
||||||
|
fullName: string;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user