This commit is contained in:
Matthias Hochmeister
2026-03-16 15:01:09 +01:00
parent 3c72fe627f
commit f3ad989a9e
28 changed files with 794 additions and 52 deletions

View File

@@ -614,6 +614,48 @@ class EventsService {
}));
}
// -------------------------------------------------------------------------
// CONFLICT CHECK
// -------------------------------------------------------------------------
/**
* Returns events that overlap with the given time range.
* Used to warn users about scheduling conflicts before creating/updating events.
*/
async checkConflicts(
datumVon: Date,
datumBis: Date,
excludeId?: string
): Promise<Array<{ id: string; titel: string; datum_von: Date; datum_bis: Date; kategorie_name: string | null }>> {
const params: any[] = [datumVon, datumBis];
let excludeClause = '';
if (excludeId) {
excludeClause = ' AND v.id != $3';
params.push(excludeId);
}
const result = await pool.query(
`SELECT v.id, v.titel, v.datum_von, v.datum_bis,
k.name AS kategorie_name
FROM veranstaltungen v
LEFT JOIN veranstaltung_kategorien k ON k.id = v.kategorie_id
WHERE v.abgesagt = FALSE
AND ($1::timestamptz, $2::timestamptz) OVERLAPS (v.datum_von, v.datum_bis)
${excludeClause}
ORDER BY v.datum_von ASC
LIMIT 10`,
params
);
return result.rows.map((row) => ({
id: row.id,
titel: row.titel,
datum_von: new Date(row.datum_von),
datum_bis: new Date(row.datum_bis),
kategorie_name: row.kategorie_name ?? null,
}));
}
// -------------------------------------------------------------------------
// ICAL EXPORT
// -------------------------------------------------------------------------