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

@@ -21,11 +21,11 @@ export class ClassSchedule {
@PrimaryGeneratedColumn()
id: number;
@Column({ name: 'class_id', type: 'integer' })
classId: number;
@Column({ name: 'class_id', type: 'integer', nullable: true })
classId: number | null;
// Forward reference — Class entity
@ManyToOne('Class')
@ManyToOne('Class', { nullable: true })
@JoinColumn({ name: 'class_id' })
class: unknown;
@@ -56,7 +56,7 @@ export class ClassSchedule {
subject: string;
@Column({ name: 'teacher_id', type: 'integer', nullable: true })
teacherId: number;
teacherId: number | null;
// Forward reference — User entity
@ManyToOne('User', { nullable: true })
@@ -67,7 +67,7 @@ export class ClassSchedule {
scheduleType: string;
@Column({ name: 'rental_id', type: 'integer', nullable: true })
rentalId: number;
rentalId: number | null;
@Column({ name: 'status', length: 20, default: 'active' })
status: string;