new features

This commit is contained in:
Matthias Hochmeister
2026-03-23 14:01:39 +01:00
parent d2dc64d54a
commit 3326156b15
35 changed files with 1341 additions and 257 deletions

View File

@@ -299,6 +299,15 @@ class VehicleService {
]
);
// Record status change history
if (oldStatus !== status) {
await client.query(
`INSERT INTO fahrzeug_status_historie (fahrzeug_id, alter_status, neuer_status, bemerkung, geaendert_von)
VALUES ($1, $2, $3, $4, $5)`,
[id, oldStatus, status, bemerkung || null, updatedBy]
);
}
await client.query('COMMIT');
logger.info('Vehicle status updated', { id, from: oldStatus, to: status, by: updatedBy });
@@ -574,6 +583,48 @@ class VehicleService {
throw new Error('Failed to fetch inspection alerts');
}
}
// =========================================================================
// STATUS HISTORY
// =========================================================================
async getStatusHistory(fahrzeugId: string) {
try {
const result = await pool.query(
`SELECT h.*, u.display_name AS geaendert_von_name
FROM fahrzeug_status_historie h
LEFT JOIN users u ON u.id = h.geaendert_von
WHERE h.fahrzeug_id = $1
ORDER BY h.erstellt_am DESC
LIMIT 50`,
[fahrzeugId]
);
return result.rows;
} catch (error) {
logger.error('VehicleService.getStatusHistory failed', { error, fahrzeugId });
throw new Error('Status-Historie konnte nicht geladen werden');
}
}
// =========================================================================
// WARTUNGSLOG FILE UPLOAD
// =========================================================================
async updateWartungslogFile(wartungId: number, filePath: string) {
try {
const result = await pool.query(
`UPDATE fahrzeug_wartungslog SET dokument_url = $1 WHERE id = $2 RETURNING *`,
[filePath, wartungId]
);
if (result.rows.length === 0) {
throw new Error('Wartungseintrag nicht gefunden');
}
return result.rows[0];
} catch (error) {
logger.error('VehicleService.updateWartungslogFile failed', { error, wartungId });
throw error;
}
}
}
export default new VehicleService();