parent
955e11846b
commit
0af9b81b38
|
@ -1,5 +1,6 @@
|
|||
import { Authorized, Body, JsonController, Post, QueryParam, Res } from 'routing-controllers';
|
||||
import { OpenAPI } from 'routing-controllers-openapi';
|
||||
import { CertificateRunner } from '../models/CertificateRunner';
|
||||
import { Runner } from '../models/Runner';
|
||||
import { RunnerCard } from '../models/RunnerCard';
|
||||
import { PdfCreator } from '../PdfCreator';
|
||||
|
@ -54,6 +55,25 @@ export class PdfController {
|
|||
return contracts;
|
||||
}
|
||||
|
||||
@Post('/certificates')
|
||||
@OpenAPI({ description: "Generate runner certificate pdfs from certificate 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 generateCertificates(@Body({ validate: true, options: { limit: "500mb" } }) runners: CertificateRunner[], @Res() res: any, @QueryParam("locale") locale: string, @QueryParam("download") download: boolean) {
|
||||
if (!this.initialized) {
|
||||
await this.pdf.init();
|
||||
this.initialized = true;
|
||||
}
|
||||
if (!Array.isArray(runners)) {
|
||||
runners = [runners];
|
||||
}
|
||||
runners = this.mapCertificatRunnersGroupNames(runners)
|
||||
const certificates = await this.pdf.generateRunnerCertficates(runners, locale);
|
||||
res.setHeader('content-type', 'application/pdf');
|
||||
if (download) {
|
||||
res.setHeader('Content-Disposition', 'attachment; filename="certificates.pdf"')
|
||||
}
|
||||
return certificates;
|
||||
}
|
||||
|
||||
private mapRunnerGroupNames(runners: Runner[]): Runner[] {
|
||||
let response = new Array<Runner>();
|
||||
for (let runner of runners) {
|
||||
|
@ -68,6 +88,20 @@ export class PdfController {
|
|||
return response;
|
||||
}
|
||||
|
||||
private mapCertificatRunnersGroupNames(runners: CertificateRunner[]): CertificateRunner[] {
|
||||
let response = new Array<CertificateRunner>();
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue