Sortieungsoptionen in Verwaltung, Umstellung der PDF generation auf generierung bei abgabe und ablage auf dem Sateisystem um einen Festen Stand zu garantieren

This commit is contained in:
2026-03-17 16:20:36 +01:00
parent 2aa4e6f037
commit a92694f693
8 changed files with 386 additions and 14 deletions

View File

@@ -0,0 +1,44 @@
const fs = require('fs');
const fsp = require('fs/promises');
const path = require('path');
const { buildTimesheetPdfLocation, getPdfBaseDir } = require('../helpers/pdf-paths');
async function ensureDirectoryExists(dirPath) {
await fsp.mkdir(dirPath, { recursive: true });
}
async function fileExists(filePath) {
try {
await fsp.access(filePath, fs.constants.F_OK);
return true;
} catch {
return false;
}
}
async function savePdfBufferAtomic(targetPath, buffer) {
const dir = path.dirname(targetPath);
await ensureDirectoryExists(dir);
const tmpPath = `${targetPath}.tmp-${process.pid}-${Date.now()}`;
await fsp.writeFile(tmpPath, buffer);
await fsp.rename(tmpPath, targetPath);
}
function resolvePdfLocationFromTimesheetRow(timesheetRow) {
return buildTimesheetPdfLocation(timesheetRow);
}
function resolveAbsolutePathFromRelative(relativePath) {
const baseDir = getPdfBaseDir();
return path.join(baseDir, relativePath);
}
module.exports = {
ensureDirectoryExists,
fileExists,
savePdfBufferAtomic,
resolvePdfLocationFromTimesheetRow,
resolveAbsolutePathFromRelative,
};