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

@@ -256,6 +256,13 @@ class EquipmentService {
updatedBy: string
): Promise<void> {
try {
// Get old status for history
const oldResult = await pool.query(
`SELECT status FROM ausruestung WHERE id = $1 AND deleted_at IS NULL`,
[id]
);
const oldStatus = oldResult.rows[0]?.status;
const result = await pool.query(
`UPDATE ausruestung
SET status = $1, status_bemerkung = $2, updated_at = NOW()
@@ -268,6 +275,15 @@ class EquipmentService {
throw new Error('Equipment not found');
}
// Record status change history
if (oldStatus && oldStatus !== status) {
await pool.query(
`INSERT INTO ausruestung_status_historie (ausruestung_id, alter_status, neuer_status, bemerkung, geaendert_von)
VALUES ($1, $2, $3, $4, $5)`,
[id, oldStatus, status, bemerkung || null, updatedBy]
);
}
logger.info('Equipment status updated', { id, status, by: updatedBy });
} catch (error) {
logger.error('EquipmentService.updateStatus failed', { error, id });
@@ -422,6 +438,48 @@ class EquipmentService {
throw new Error('Failed to fetch upcoming inspections');
}
}
// =========================================================================
// STATUS HISTORY
// =========================================================================
async getStatusHistory(equipmentId: string) {
try {
const result = await pool.query(
`SELECT h.*, u.display_name AS geaendert_von_name
FROM ausruestung_status_historie h
LEFT JOIN users u ON u.id = h.geaendert_von
WHERE h.ausruestung_id = $1
ORDER BY h.erstellt_am DESC
LIMIT 50`,
[equipmentId]
);
return result.rows;
} catch (error) {
logger.error('EquipmentService.getStatusHistory failed', { error, equipmentId });
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 ausruestung_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('EquipmentService.updateWartungslogFile failed', { error, wartungId });
throw error;
}
}
}
export default new EquipmentService();