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:
+12
-1
@@ -223,10 +223,21 @@ function generatePDF(event) {
|
|||||||
fetch(url).then(res => res.json())
|
fetch(url).then(res => res.json())
|
||||||
])
|
])
|
||||||
.then(([_loaded, settings, applications]) => {
|
.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);
|
generatePdfDocument(settings, applications, month, year);
|
||||||
hideModal(pdfExportModal);
|
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
|
// PDF Generation with jsPDF
|
||||||
|
|||||||
@@ -2048,15 +2048,15 @@ initializeDatabase().then(async () => {
|
|||||||
const params = [U, U];
|
const params = [U, U];
|
||||||
|
|
||||||
if (month && year) {
|
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);
|
params.push(month.padStart(2, '0'), year);
|
||||||
} else if (month) {
|
} else if (month) {
|
||||||
// A month without a year must still restrict the export to that month —
|
// A month without a year must still restrict the export to that month —
|
||||||
// never fall through to exporting every application.
|
// 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'));
|
params.push(month.padStart(2, '0'));
|
||||||
} else if (year) {
|
} 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);
|
params.push(year);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user