Per-Anbieter default VO with auto-select in the schaltung wizard
- New nullable anbieter.default_vo_id column (migration adds it to existing DBs); deleting a VO that some provider points at clears the reference automatically. - GET /api/anbieter now includes default_vo_id + default_vo_nummer + default_vo_bezeichnung so the wizard can preselect without an extra round-trip. - New PUT /api/anbieter/:id/default-vo endpoint. Validates the VO belongs to the given provider; accepts vo_id=null to clear. - VO admin table grew a "Standard" column and an "Als Standard" / "Standard entfernen" button on each row. - When the user picks a provider in step 1 of the wizard, the VO dropdown now preselects the default VO (falling back to the only VO if there is exactly one), and immediately loads the matching tariffs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
97ff779bcf
commit
041df61b24
5 files changed
+82
-16
No files matched your search
+23
-1
@@ -5,10 +5,32 @@ const asyncHandler = require('../middleware/asyncHandler');
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/', asyncHandler(async (req, res) => {
|
||||
const rows = await db.all('SELECT * FROM anbieter ORDER BY name');
|
||||
const rows = await db.all(
|
||||
`SELECT a.*, v.nummer AS default_vo_nummer, v.bezeichnung AS default_vo_bezeichnung
|
||||
FROM anbieter a
|
||||
LEFT JOIN vos v ON a.default_vo_id = v.id
|
||||
ORDER BY a.name`
|
||||
);
|
||||
res.json(rows);
|
||||
}));
|
||||
|
||||
// Set or clear the default VO for a provider. Pass vo_id=null to clear.
|
||||
router.put('/:id/default-vo', asyncHandler(async (req, res) => {
|
||||
const { id } = req.params;
|
||||
const { vo_id } = req.body || {};
|
||||
const anbieter = await db.get('SELECT id FROM anbieter WHERE id = ?', [id]);
|
||||
if (!anbieter) return res.status(404).json({ error: 'Anbieter nicht gefunden' });
|
||||
if (vo_id) {
|
||||
const vo = await db.get('SELECT anbieter_id FROM vos WHERE id = ?', [vo_id]);
|
||||
if (!vo) return res.status(400).json({ error: 'VO nicht gefunden' });
|
||||
if (vo.anbieter_id !== Number(id)) {
|
||||
return res.status(400).json({ error: 'VO gehört nicht zu diesem Anbieter' });
|
||||
}
|
||||
}
|
||||
await db.run('UPDATE anbieter SET default_vo_id = ? WHERE id = ?', [vo_id || null, id]);
|
||||
res.json({ message: 'Standard-VO aktualisiert', default_vo_id: vo_id || null });
|
||||
}));
|
||||
|
||||
router.post('/', asyncHandler(async (req, res) => {
|
||||
const { name } = req.body || {};
|
||||
if (!name || !name.trim()) {
|
||||
|
||||
Reference in new issue
Block a user