base structure for list printing with custom template

This commit is contained in:
Julian Krauser 2025-03-18 16:54:53 +01:00
parent e2a916f37d
commit a085de6e2f
19 changed files with 279 additions and 98 deletions

View file

@ -0,0 +1,52 @@
import { Request, Response } from "express";
import { PdfExport } from "../../../helpers/pdfExport";
import DynamicQueryBuilder from "../../../helpers/dynamicQueryBuilder";
import QueryStoreService from "../../../service/configuration/queryStoreService";
/**
* @description print list by query and template
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function printListByQueryAndTemplate(req: Request, res: Response): Promise<any> {
const title = req.body.title;
const queryStore = req.body.queryStore;
const headerId = req.body.headerId ?? null;
const bodyId = req.body.bodyId ?? null;
const footerId = req.body.footerId ?? null;
const headerHeight = req.body.headerHeight ?? null;
const footerHeight = req.body.footerHeight ?? null;
// \/ integrate into query builder execution via shortcut
//await MemberService.getByRunningMembership();
//await MemberService.getAll({ noLimit:true });
let query = (await QueryStoreService.getById(queryStore)).query;
await DynamicQueryBuilder.executeQuery({ query, noLimit: true });
let pdf = await PdfExport.renderFile({
title: title,
template: "listprint",
saveToDisk: false,
data: {
today: new Date(),
},
customTemplate: {
headerId,
footerId,
bodyId,
headerHeight,
footerHeight,
},
});
let pdfbuffer = Buffer.from(pdf);
res.setHeader("Content-Type", "application/pdf");
res.setHeader("Content-Length", pdfbuffer.byteLength);
res.setHeader("Content-Disposition", "inline; filename=preview.pdf");
res.send(pdfbuffer);
}

View file

@ -305,33 +305,6 @@ export async function getCommunicationByMemberAndRecord(req: Request, res: Respo
res.json(CommunicationFactory.mapToSingle(communication));
}
/**
* @description create member printout list
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function createMemberPrintoutList(req: Request, res: Response): Promise<any> {
let members = await MemberService.getByRunningMembership();
let pdf = await PdfExport.renderFile({
title: "Mitgliederliste",
template: "member.list",
saveToDisk: false,
data: {
member: members,
},
});
let pdfbuffer = Buffer.from(pdf);
res.setHeader("Content-Type", "application/pdf");
res.setHeader("Content-Length", pdfbuffer.byteLength);
res.setHeader("Content-Disposition", "inline; filename=preview.pdf");
res.send(pdfbuffer);
}
/**
* @description create member
* @param req {Request} Express req object