From 2339e12410e29a9444def6f7b15ddecab476c1b4 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Sat, 25 Apr 2026 10:00:50 +0200 Subject: [PATCH] feat(BillingController, BillingService): enhance billing template handling and error logging - Updated billingController to use a dynamic upload directory for billing templates, improving file management. - Added error handling in billingService to log warnings when templates are missing or not found, enhancing debugging capabilities. - Improved user feedback by returning specific error messages when template-related issues occur during billing runs. --- backend/controllers/billingController.js | 7 ++++++- backend/services/billingService.js | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/backend/controllers/billingController.js b/backend/controllers/billingController.js index 1de5752a..b544f652 100644 --- a/backend/controllers/billingController.js +++ b/backend/controllers/billingController.js @@ -1,11 +1,16 @@ import fs from 'fs'; import multer from 'multer'; import path from 'path'; +import { fileURLToPath } from 'url'; import billingService from '../services/billingService.js'; +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const BILLING_TEMPLATE_UPLOAD_DIR = path.resolve(__dirname, '..', 'uploads', 'billing-templates'); + const storage = multer.diskStorage({ destination: (req, file, cb) => { - const dir = 'uploads/billing-templates'; + const dir = BILLING_TEMPLATE_UPLOAD_DIR; fs.mkdirSync(dir, { recursive: true }); cb(null, dir); }, diff --git a/backend/services/billingService.js b/backend/services/billingService.js index 43b26262..c39523b9 100644 --- a/backend/services/billingService.js +++ b/backend/services/billingService.js @@ -613,8 +613,23 @@ class BillingService { return { status: 404, response: { success: false, error: 'Abrechnungslauf nicht gefunden' } }; } await checkAccess(userToken, run.clubId); + if (!run.template) { + console.warn('[billing.generateRun] Vorlage fehlt für Run', { + runId: run.id, + clubId: run.clubId, + templateId: run.templateId + }); + return { status: 404, response: { success: false, error: 'Vorlage für diesen Abrechnungslauf nicht gefunden. Bitte neuen Abrechnungslauf mit aktueller Vorlage erstellen.' } }; + } const resolvedTemplatePath = this._resolveExistingFilePath(run.template?.pdfStoragePath); if (!resolvedTemplatePath) { + console.warn('[billing.generateRun] Vorlagen-PDF nicht gefunden', { + runId: run.id, + clubId: run.clubId, + templateId: run.templateId, + storedPath: run.template?.pdfStoragePath, + cwd: process.cwd() + }); return { status: 404, response: { success: false, error: 'Vorlagen-PDF nicht gefunden' } }; } const computed = await this._collectTrainingSessions(run.clubId, run.periodStart, run.periodEnd);