update
This commit is contained in:
@@ -216,6 +216,45 @@ class AtemschutzService {
|
||||
}
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// EXPIRING CERTIFICATIONS
|
||||
// =========================================================================
|
||||
|
||||
async getExpiringCertifications(daysAhead = 30): Promise<any[]> {
|
||||
try {
|
||||
const result = await pool.query(`
|
||||
SELECT
|
||||
at.id, at.user_id, u.email,
|
||||
COALESCE(u.name, u.email) as user_name,
|
||||
at.untersuchung_gueltig_bis,
|
||||
at.leistungstest_gueltig_bis,
|
||||
CASE
|
||||
WHEN at.untersuchung_gueltig_bis < CURRENT_DATE THEN 'abgelaufen'
|
||||
WHEN at.untersuchung_gueltig_bis <= CURRENT_DATE + $1 THEN 'bald_faellig'
|
||||
ELSE 'ok'
|
||||
END as untersuchung_status,
|
||||
CASE
|
||||
WHEN at.leistungstest_gueltig_bis < CURRENT_DATE THEN 'abgelaufen'
|
||||
WHEN at.leistungstest_gueltig_bis <= CURRENT_DATE + $1 THEN 'bald_faellig'
|
||||
ELSE 'ok'
|
||||
END as leistungstest_status
|
||||
FROM atemschutz_traeger at
|
||||
JOIN users u ON u.id = at.user_id
|
||||
WHERE at.einsatzbereit = TRUE
|
||||
AND (
|
||||
at.untersuchung_gueltig_bis <= CURRENT_DATE + $1
|
||||
OR at.leistungstest_gueltig_bis <= CURRENT_DATE + $1
|
||||
)
|
||||
ORDER BY LEAST(at.untersuchung_gueltig_bis, at.leistungstest_gueltig_bis) ASC
|
||||
`, [`${daysAhead} days`]);
|
||||
|
||||
return result.rows;
|
||||
} catch (error) {
|
||||
logger.error('AtemschutzService.getExpiringCertifications fehlgeschlagen', { error });
|
||||
throw new Error('Ablaufende Atemschutz-Zertifizierungen konnten nicht geladen werden');
|
||||
}
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// DASHBOARD KPI / STATISTIKEN
|
||||
// =========================================================================
|
||||
|
||||
Reference in New Issue
Block a user