refactor: resolve remaining field audit issues

This commit is contained in:
2026-07-13 15:12:36 +08:00
parent 0533c30ece
commit aa1ed7db56
34 changed files with 953 additions and 263 deletions

View File

@@ -11,6 +11,7 @@ import {
ClassSchedule,
Class,
Classroom,
ClassroomStatus,
ClassroomRental,
ClassTeacher,
AttendanceSession,
@@ -83,7 +84,7 @@ export class SchedulesService {
});
const classrooms = await this.classroomRepo.find({
where: { status: Not('archived') },
where: { status: ClassroomStatus.AVAILABLE },
select: ['id', 'name', 'building', 'floor', 'roomType'],
order: { building: 'ASC', name: 'ASC' },
});
@@ -159,7 +160,16 @@ export class SchedulesService {
return schedule;
}
private async assertClassroomAvailable(classroomId: number) {
const classroom = await this.classroomRepo.findOne({ where: { id: classroomId } });
if (!classroom) throw new NotFoundException('教室不存在');
if (classroom.status !== ClassroomStatus.AVAILABLE) {
throw new BadRequestException('仅可用教室可以排课');
}
}
async create(dto: CreateScheduleDto) {
await this.assertClassroomAvailable(dto.classroomId);
await this.normalizeTeacherForSchedule(dto);
await this.assertTeacherAssignedToClass(dto.classId, dto.teacherId);
await this.checkConflict(
@@ -182,6 +192,9 @@ export class SchedulesService {
// If classroom, weekDay, or times are changing, check conflicts excluding self
const classroomId = dto.classroomId ?? existing.classroomId;
if (dto.classroomId !== undefined && dto.classroomId !== existing.classroomId) {
await this.assertClassroomAvailable(dto.classroomId);
}
const weekDay = dto.weekDay ?? existing.weekDay;
const startTime = dto.startTime ?? existing.startTime;
const endTime = dto.endTime ?? existing.endTime;
@@ -253,7 +266,7 @@ export class SchedulesService {
const rentalConflicts = await this.rentalRepo
.createQueryBuilder('r')
.where('r.classroomId = :classroomId', { classroomId })
.andWhere('r.status != :cancelled', { cancelled: 'cancelled' })
.andWhere('r.status = :activeRental', { activeRental: 'active' })
.andWhere('r.startDate <= :endDate', { endDate })
.andWhere('r.endDate >= :startDate', { startDate })
.getMany();