update
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Request, Response } from 'express';
|
||||
import atemschutzService from '../services/atemschutz.service';
|
||||
import notificationService from '../services/notification.service';
|
||||
import { CreateAtemschutzSchema, UpdateAtemschutzSchema } from '../models/atemschutz.model';
|
||||
import logger from '../utils/logger';
|
||||
|
||||
@@ -159,6 +160,49 @@ class AtemschutzController {
|
||||
}
|
||||
}
|
||||
|
||||
async getExpiring(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const expiring = await atemschutzService.getExpiringCertifications(30);
|
||||
|
||||
// Side-effect: create notifications for expiring certifications (dedup via DB constraint)
|
||||
for (const item of expiring) {
|
||||
if (item.untersuchung_status !== 'ok') {
|
||||
await notificationService.createNotification({
|
||||
user_id: item.user_id,
|
||||
typ: 'atemschutz_expiry',
|
||||
titel: item.untersuchung_status === 'abgelaufen'
|
||||
? 'G26 Untersuchung abgelaufen'
|
||||
: 'G26 Untersuchung läuft bald ab',
|
||||
nachricht: `Ihre G26 Untersuchung ${item.untersuchung_status === 'abgelaufen' ? 'ist abgelaufen' : 'läuft bald ab'}.`,
|
||||
schwere: item.untersuchung_status === 'abgelaufen' ? 'fehler' : 'warnung',
|
||||
quell_typ: 'atemschutz_untersuchung',
|
||||
quell_id: item.id,
|
||||
link: '/atemschutz',
|
||||
});
|
||||
}
|
||||
if (item.leistungstest_status !== 'ok') {
|
||||
await notificationService.createNotification({
|
||||
user_id: item.user_id,
|
||||
typ: 'atemschutz_expiry',
|
||||
titel: item.leistungstest_status === 'abgelaufen'
|
||||
? 'Leistungstest abgelaufen'
|
||||
: 'Leistungstest läuft bald ab',
|
||||
nachricht: `Ihr Leistungstest ${item.leistungstest_status === 'abgelaufen' ? 'ist abgelaufen' : 'läuft bald ab'}.`,
|
||||
schwere: item.leistungstest_status === 'abgelaufen' ? 'fehler' : 'warnung',
|
||||
quell_typ: 'atemschutz_leistungstest',
|
||||
quell_id: item.id,
|
||||
link: '/atemschutz',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
res.status(200).json({ success: true, data: expiring });
|
||||
} catch (error) {
|
||||
logger.error('Atemschutz getExpiring error', { error });
|
||||
res.status(500).json({ success: false, message: 'Ablaufende Zertifizierungen konnten nicht geladen werden' });
|
||||
}
|
||||
}
|
||||
|
||||
async delete(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const { id } = req.params as Record<string, string>;
|
||||
|
||||
Reference in New Issue
Block a user