feat(BillingController, BillingService): enhance billing template handling and error logging
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 41s

- 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.
This commit is contained in:
Torsten Schulz (local)
2026-04-25 10:00:50 +02:00
parent be9d26e51e
commit 2339e12410
2 changed files with 21 additions and 1 deletions

View File

@@ -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);
},

View File

@@ -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);