Task 3: sync RENTAL class_schedule on rental create/update/delete

- ClassroomRentalsService.create/update now upsert a ClassSchedule row with schedule_type='RENTAL' and rental_id set.
- ClassroomRentalsService.remove deletes the synced schedule row; update to 'cancelled' also removes it.
- SchedulesService.getClassroomOccupancy explicitly returns INTERNAL and RENTAL schedules.
- Make classId/teacherId/rentalId nullable in ClassSchedule entity to support rental schedules.
- Add unit tests for rental schedule sync and mixed-type occupancy.
This commit is contained in:
2026-07-06 17:55:08 +08:00
parent 5ea49d0a9e
commit 38f6e18cca
6 changed files with 310 additions and 10 deletions

View File

@@ -85,7 +85,7 @@ export class SchedulesController {
const conflicts = await this.service.checkConflict(
dto.classroomId, dto.weekDay, dto.startTime, dto.endTime, dto.startDate, dto.endDate,
);
const teacherIds = [...new Set(conflicts.map(c => c.teacherId).filter(Boolean))];
const teacherIds = [...new Set(conflicts.map(c => c.teacherId).filter((id): id is number => id != null))];
if (teacherIds.length > 0) {
void this.notificationsService.create({
recipientIds: teacherIds,
@@ -129,7 +129,7 @@ export class SchedulesController {
const conflicts = await this.service.checkConflict(
existing.classroomId, existing.weekDay, existing.startTime, existing.endTime, existing.startDate, existing.endDate,
);
const teacherIds = [...new Set(conflicts.map(c => c.teacherId).filter(Boolean))];
const teacherIds = [...new Set(conflicts.map(c => c.teacherId).filter((id): id is number => id != null))];
if (teacherIds.length > 0) {
void this.notificationsService.create({
recipientIds: teacherIds,