This commit is contained in:
Julian Krauser 2024-10-19 16:24:41 +02:00
parent 58213923e5
commit 9da2a98f55
12 changed files with 341 additions and 54 deletions

View file

@ -23,6 +23,10 @@ import { SynchronizeProtocolVotingCommand } from "../../command/protocolVotingCo
import { ProtocolVotingViewModel } from "../../viewmodel/admin/protocolVoting.models";
import ProtocolVotingCommandHandler from "../../command/protocolVotingCommandHandler";
import { PdfExport } from "../../helpers/pdfExport";
import ProtocolPrintoutService from "../../service/protocolPrintoutService";
import ProtocolPrintoutFactory from "../../factory/admin/protocolPrintout";
import { CreateProtocolPrintoutCommand } from "../../command/protocolPrintoutCommand";
import ProtocolPrintoutCommandHandler from "../../command/protocolPrintoutCommandHandler";
/**
* @description get all protocols
@ -112,6 +116,35 @@ export async function getProtocolVotingsById(req: Request, res: Response): Promi
res.json(ProtocolVotingFactory.mapToBase(votings));
}
/**
* @description get protocol printouts by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getProtocolPrintoutsById(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let printouts = await ProtocolPrintoutService.getAll(protocolId);
res.json(ProtocolPrintoutFactory.mapToBase(printouts));
}
/**
* @description get protocol printout by id and print
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getProtocolPrintoutByIdAndPrint(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let printoutId = parseInt(req.params.printoutId);
let printouts = await ProtocolPrintoutService.getById(printoutId, protocolId);
res.json(ProtocolPrintoutFactory.mapToSingle(printouts));
}
/**
* @description create protocol
* @param req {Request} Express req object
@ -173,6 +206,69 @@ export async function createProtocolVotingsById(req: Request, res: Response): Pr
res.send(voting);
}
/**
* @description create protocol printout by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function createProtocolPrintoutById(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let protocol = await ProtocolService.getById(protocolId);
let agenda = await ProtocolAgendaService.getAll(protocolId);
let decisions = await ProtocolDecisionService.getAll(protocolId);
let presence = await ProtocolPresenceService.getAll(protocolId);
let votings = await ProtocolVotingService.getAll(protocolId);
let iteration = await ProtocolPrintoutService.getCount(protocolId);
let title = `Sitzungsprotokoll - ${new Date(protocol.date).toLocaleDateString("de-DE", {
day: "2-digit",
month: "long",
year: "numeric",
})}`;
let filename = `P_${protocol.title.replace(/[^a-zA-Z0-9]/g, "")}_${iteration + 1}_${new Date().toLocaleDateString()}`;
await PdfExport.renderFile({
template: "protocol.template.html",
title,
filename,
data: {
title: protocol.title,
summary: protocol.summary,
iteration: iteration + 1,
date: new Date(protocol.date).toLocaleDateString("de-DE", {
weekday: "long",
day: "2-digit",
month: "2-digit",
year: "numeric",
}),
start: new Date(protocol.starttime).toLocaleTimeString("de-DE", {
minute: "2-digit",
hour: "2-digit",
}),
end: new Date(protocol.endtime).toLocaleTimeString("de-DE", {
minute: "2-digit",
hour: "2-digit",
}),
agenda,
decisions,
presence: presence.map((p) => p.member),
votings,
},
});
let printout: CreateProtocolPrintoutCommand = {
title,
iteration: iteration + 1,
filename,
protocolId,
};
await ProtocolPrintoutCommandHandler.create(printout);
res.sendStatus(204);
}
/**
* @description synchronize protocol by id
* @param req {Request} Express req object
@ -290,47 +386,3 @@ export async function synchronizeProtocolPrecenseById(req: Request, res: Respons
res.sendStatus(204);
}
/**
* @description render protocol to file by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function printPdf(req: Request, res: Response): Promise<any> {
let protocolId = parseInt(req.params.protocolId);
let protocol = await ProtocolService.getById(protocolId);
let agenda = await ProtocolAgendaService.getAll(protocolId);
let decisions = await ProtocolDecisionService.getAll(protocolId);
let presence = await ProtocolPresenceService.getAll(protocolId);
let votings = await ProtocolVotingService.getAll(protocolId);
await PdfExport.renderFile({
template: "protocol.template.html",
title: protocol.title,
data: {
title: protocol.title,
summary: protocol.summary,
date: new Date(protocol.date).toLocaleDateString("de-DE", {
weekday: "long",
day: "2-digit",
month: "2-digit",
year: "numeric",
}),
start: new Date(protocol.starttime).toLocaleTimeString("de-DE", {
minute: "2-digit",
hour: "2-digit",
}),
end: new Date(protocol.endtime).toLocaleTimeString("de-DE", {
minute: "2-digit",
hour: "2-digit",
}),
agenda,
decisions,
presence: presence.map((p) => p.member),
votings,
},
});
res.sendStatus(204);
}