parent
19697692bc
commit
75eb925267
@ -46,6 +46,8 @@
|
|||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"handlebars": "^4.7.6",
|
"handlebars": "^4.7.6",
|
||||||
|
"i18next": "^19.8.7",
|
||||||
|
"i18next-fs-backend": "^1.0.8",
|
||||||
"puppeteer": "^7.0.1",
|
"puppeteer": "^7.0.1",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"routing-controllers": "^0.9.0-alpha.6",
|
"routing-controllers": "^0.9.0-alpha.6",
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import Handlebars from 'handlebars';
|
||||||
|
import i18next from "i18next";
|
||||||
|
import Backend from 'i18next-fs-backend';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import puppeteer from "puppeteer";
|
import puppeteer from "puppeteer";
|
||||||
import { Runner } from './models/Runner';
|
import { Runner } from './models/Runner';
|
||||||
import Handlebars = require('handlebars');
|
|
||||||
/**
|
/**
|
||||||
* This class is responsible for all things pdf creation.
|
* This class is responsible for all things pdf creation.
|
||||||
* This uses the html templates from src/templates.
|
* This uses the html templates from src/templates.
|
||||||
@ -12,12 +15,25 @@ export class PdfCreator {
|
|||||||
private browser;
|
private browser;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
i18next
|
||||||
|
.use(Backend)
|
||||||
|
.init({
|
||||||
|
fallbackLng: 'en',
|
||||||
|
lng: 'en',
|
||||||
|
backend: {
|
||||||
|
loadPath: path.join(__dirname, '/locales/{{lng}}.json')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Handlebars.registerHelper('__',
|
||||||
|
function (str) {
|
||||||
|
return i18next.t(str).toString();
|
||||||
|
}
|
||||||
|
);
|
||||||
puppeteer.launch({ headless: true }).then(browser => {
|
puppeteer.launch({ headless: true }).then(browser => {
|
||||||
this.browser = browser;
|
this.browser = browser;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Accept the runner class
|
|
||||||
public async generateSponsoringContract(runner: Runner): Promise<any> {
|
public async generateSponsoringContract(runner: Runner): Promise<any> {
|
||||||
const template_source = fs.readFileSync(`${this.templateDir}/sponsoring_contract.html`, 'utf8');
|
const template_source = fs.readFileSync(`${this.templateDir}/sponsoring_contract.html`, 'utf8');
|
||||||
const template = Handlebars.compile(template_source);
|
const template = Handlebars.compile(template_source);
|
||||||
|
@ -13,7 +13,6 @@ export class PdfController {
|
|||||||
@Post('/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: Runner, @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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user