feat: vehicle/equipment type system, equipment checklist support, and checklist overview redesign
This commit is contained in:
@@ -13,15 +13,19 @@ async function runChecklistReminderCheck(): Promise<void> {
|
||||
}
|
||||
isRunning = true;
|
||||
try {
|
||||
// Find overdue checklists
|
||||
// Find overdue checklists (vehicles + equipment)
|
||||
const result = await pool.query(`
|
||||
SELECT cf.fahrzeug_id, cf.vorlage_id, cf.naechste_faellig_am,
|
||||
SELECT cf.fahrzeug_id, cf.ausruestung_id, cf.vorlage_id, cf.naechste_faellig_am,
|
||||
f.bezeichnung AS fahrzeug_name,
|
||||
ar.name AS ausruestung_name,
|
||||
v.name AS vorlage_name
|
||||
FROM checklist_faelligkeit cf
|
||||
JOIN fahrzeuge f ON f.id = cf.fahrzeug_id AND f.deleted_at IS NULL
|
||||
LEFT JOIN fahrzeuge f ON f.id = cf.fahrzeug_id AND f.deleted_at IS NULL
|
||||
LEFT JOIN ausruestung ar ON ar.id = cf.ausruestung_id
|
||||
JOIN checklist_vorlagen v ON v.id = cf.vorlage_id AND v.aktiv = true
|
||||
WHERE cf.naechste_faellig_am <= CURRENT_DATE
|
||||
AND (cf.fahrzeug_id IS NOT NULL OR cf.ausruestung_id IS NOT NULL)
|
||||
AND (cf.fahrzeug_id IS NULL OR f.id IS NOT NULL)
|
||||
`);
|
||||
|
||||
if (result.rows.length === 0) return;
|
||||
@@ -40,16 +44,21 @@ async function runChecklistReminderCheck(): Promise<void> {
|
||||
day: '2-digit', month: '2-digit', year: 'numeric',
|
||||
});
|
||||
|
||||
// Notify first responsible user (avoid spam by using quell_id dedup)
|
||||
const targetName = row.fahrzeug_name || row.ausruestung_name || 'Unbekannt';
|
||||
const quellId = row.fahrzeug_id
|
||||
? `${row.fahrzeug_id}_${row.vorlage_id}`
|
||||
: `eq_${row.ausruestung_id}_${row.vorlage_id}`;
|
||||
|
||||
// Notify responsible users (dedup handled by quell_id)
|
||||
for (const userId of targetUserIds) {
|
||||
await notificationService.createNotification({
|
||||
user_id: userId,
|
||||
typ: 'checklist_faellig',
|
||||
titel: `Checkliste überfällig: ${row.vorlage_name}`,
|
||||
nachricht: `Die Checkliste "${row.vorlage_name}" für ${row.fahrzeug_name} war fällig am ${faelligDatum}`,
|
||||
nachricht: `Die Checkliste "${row.vorlage_name}" für ${targetName} war fällig am ${faelligDatum}`,
|
||||
schwere: 'warnung',
|
||||
link: `/checklisten`,
|
||||
quell_id: `${row.fahrzeug_id}_${row.vorlage_id}`,
|
||||
quell_id: quellId,
|
||||
quell_typ: 'checklist_faellig',
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user