fix: return 409 on duplicate kontonummer, show server error in snackbar, block save when sub-account suffix is empty

This commit is contained in:
Matthias Hochmeister
2026-03-30 11:03:53 +02:00
parent 2e736f7995
commit b7015ace84
3 changed files with 9 additions and 5 deletions

View File

@@ -167,9 +167,10 @@ class BuchhaltungController {
try {
const data = await buchhaltungService.createKonto(req.body, req.user!.id);
res.status(201).json({ success: true, data });
} catch (error) {
} catch (error: any) {
logger.error('BuchhaltungController.createKonto', { error });
res.status(500).json({ success: false, message: 'Konto konnte nicht erstellt werden' });
const status = error.statusCode || 500;
res.status(status).json({ success: false, message: error.message || 'Konto konnte nicht erstellt werden' });
}
}

View File

@@ -375,8 +375,11 @@ async function createKonto(
[data.haushaltsjahr_id, data.konto_typ_id || null, data.kontonummer, data.bezeichnung, data.parent_id || null, data.budget_gwg || 0, data.budget_anlagen || 0, data.budget_instandhaltung || 0, data.notizen || null, userId]
);
return result.rows[0];
} catch (error) {
} catch (error: any) {
logger.error('BuchhaltungService.createKonto failed', { error });
if (error.code === '23505' && error.constraint === 'buchhaltung_konten_haushaltsjahr_id_kontonummer_key') {
throw Object.assign(new Error(`Kontonummer "${data.kontonummer}" existiert bereits in diesem Haushaltsjahr`), { statusCode: 409 });
}
throw new Error('Konto konnte nicht erstellt werden');
}
}