PDF-Export: /api/export monats/jahresbezogen gab 500 (ungueltiges SQL)

Die gefilterten Export-Zweige bauten `SELECT * FROM (<subquery>) AND
strftime(...)` — ohne WHERE nach der abgeleiteten Tabelle. SQLite
quittierte das mit "near \"AND\": syntax error" => HTTP 500, der Client
erhielt {error:'Serverfehler'} statt des Bewerbungs-Arrays und
generatePdfDocument crashte mit "applications.map is not a function".

Fix: `AND` => `WHERE` in den drei gefilterten Zweigen (month+year,
month, year). Die Per-User-Isolation bleibt unberuehrt (user_id-Filter
steht weiterhin in der Subquery). Zusaetzlich prueft generatePDF jetzt
Array.isArray(applications) und zeigt eine klare Fehlermeldung statt
des .map-Crashs.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-07-14 02:38:47 +02:00
co-authored by Claude
parent 69e6a29d87
commit 295c447d58
2 changed files with 15 additions and 4 deletions
+12 -1
View File
@@ -223,10 +223,21 @@ function generatePDF(event) {
fetch(url).then(res => res.json())
])
.then(([_loaded, settings, applications]) => {
// /api/export returns an array of applications; on a server error it
// returns { error: '...' } instead. Guard so we surface a real message
// rather than crashing inside generatePdfDocument with "applications.map
// is not a function".
if (!Array.isArray(applications)) {
alert('Export fehlgeschlagen: ' + ((applications && applications.error) || 'Unbekannter Serverfehler'));
return;
}
generatePdfDocument(settings, applications, month, year);
hideModal(pdfExportModal);
})
.catch(error => console.error('Error generating PDF:', error));
.catch(error => {
console.error('Error generating PDF:', error);
alert('Export fehlgeschlagen. Bitte erneut versuchen.');
});
}
// PDF Generation with jsPDF
+3 -3
View File
@@ -2048,15 +2048,15 @@ initializeDatabase().then(async () => {
const params = [U, U];
if (month && year) {
query = `SELECT * FROM (${base}) AND strftime("%m", eff_datum) = ? AND strftime("%Y", eff_datum) = ? ORDER BY eff_datum DESC`;
query = `SELECT * FROM (${base}) WHERE strftime("%m", eff_datum) = ? AND strftime("%Y", eff_datum) = ? ORDER BY eff_datum DESC`;
params.push(month.padStart(2, '0'), year);
} else if (month) {
// A month without a year must still restrict the export to that month —
// never fall through to exporting every application.
query = `SELECT * FROM (${base}) AND strftime("%m", eff_datum) = ? ORDER BY eff_datum DESC`;
query = `SELECT * FROM (${base}) WHERE strftime("%m", eff_datum) = ? ORDER BY eff_datum DESC`;
params.push(month.padStart(2, '0'));
} else if (year) {
query = `SELECT * FROM (${base}) AND strftime("%Y", eff_datum) = ? ORDER BY eff_datum DESC`;
query = `SELECT * FROM (${base}) WHERE strftime("%Y", eff_datum) = ? ORDER BY eff_datum DESC`;
params.push(year);
}