Conflict detection across section/group hierarchy
Le problème
A seance can target a whole section (fanning out to all its groups) or a set of groups (rolling up to their sections). Naive equality checks missed overlaps between a section-level lecture and a group-level lab.
Comment je l'ai résolu
Build an audience scope that unions the section, its groups, and the parent sections of any provided groups, then run one overlap query against teacher, room, section, and group on the same session and day.
const existingSeances = await this.constructor.find({
session: this.session,
seanceDay: this.seanceDay,
$or: orConditions, // group, section, room, teacherSession
$and: [
{ startHour: { $lt: this.endHour } },
{ endHour: { $gt: this.startHour } },
],
});


