fix: review blockers — entity registration, session enum, conflict date-range, @Type decorators

This commit is contained in:
2026-07-05 20:20:43 +08:00
parent 99162168b1
commit b7117ddf2d
5 changed files with 22 additions and 5 deletions

View File

@@ -19,6 +19,9 @@ import {
ClassroomRental,
Permission,
Role,
Class,
ClassStudent,
ClassTeacher,
ClassSchedule,
AttendanceRecord,
DingAttendanceRaw,

View File

@@ -24,7 +24,7 @@ export class AttendanceRecordItem {
attendanceDate: string;
@IsString()
@IsIn(['morning', 'afternoon', 'evening'])
@IsIn(['morning_reading', 'morning', 'afternoon', 'evening_study', 'night_check'])
@IsNotEmpty()
session: string;

View File

@@ -1,4 +1,5 @@
import { IsOptional, IsString, IsNotEmpty, IsInt, IsArray, IsDateString, IsEnum } from 'class-validator';
import { Type } from 'class-transformer';
import { ClassType, ClassStatus, TeacherRoleType } from '../../entities';
export class CreateClassDto {
@@ -84,7 +85,9 @@ export class UpdateClassDto {
}
export class QueryClassDto {
@IsOptional() @IsInt()
@IsOptional()
@Type(() => Number)
@IsInt()
departmentId?: number;
@IsOptional() @IsString()

View File

@@ -8,6 +8,7 @@ import {
Min,
Max,
} from 'class-validator';
import { Type } from 'class-transformer';
export class CreateScheduleDto {
@IsInt()
@@ -115,14 +116,17 @@ export class UpdateScheduleDto {
export class QueryScheduleDto {
@IsOptional()
@Type(() => Number)
@IsInt()
classroomId?: number;
@IsOptional()
@Type(() => Number)
@IsInt()
classId?: number;
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
@Max(7)
@@ -147,6 +151,7 @@ export class WeeklyViewQueryDto {
endDate?: string;
@IsOptional()
@Type(() => Number)
@IsInt()
classroomId?: number;
}

View File

@@ -38,7 +38,7 @@ export class SchedulesService {
}
async create(dto: CreateScheduleDto) {
await this.checkConflict(dto.classroomId, dto.weekDay, dto.startTime, dto.endTime);
await this.checkConflict(dto.classroomId, dto.weekDay, dto.startTime, dto.endTime, dto.startDate, dto.endDate);
const schedule = this.scheduleRepo.create(dto);
const saved = await this.scheduleRepo.save(schedule);
@@ -54,8 +54,10 @@ export class SchedulesService {
const weekDay = dto.weekDay ?? existing.weekDay;
const startTime = dto.startTime ?? existing.startTime;
const endTime = dto.endTime ?? existing.endTime;
const startDate = dto.startDate ?? existing.startDate;
const endDate = dto.endDate ?? existing.endDate;
await this.checkConflict(classroomId, weekDay, startTime, endTime, id);
await this.checkConflict(classroomId, weekDay, startTime, endTime, startDate, endDate, id);
await this.scheduleRepo.update(id, dto as Record<string, unknown>);
return this.findOne(id);
@@ -73,6 +75,8 @@ export class SchedulesService {
weekDay: number,
startTime: string,
endTime: string,
startDate: string,
endDate: string,
excludeId?: number,
) {
const qb = this.scheduleRepo
@@ -81,7 +85,9 @@ export class SchedulesService {
.andWhere('cs.weekDay = :weekDay', { weekDay })
.andWhere('cs.status = :status', { status: 'active' })
.andWhere('cs.startTime < :endTime', { endTime })
.andWhere('cs.endTime > :startTime', { startTime });
.andWhere('cs.endTime > :startTime', { startTime })
.andWhere('cs.startDate <= :endDate', { endDate })
.andWhere('cs.endDate >= :startDate', { startDate });
if (excludeId) qb.andWhere('cs.id != :excludeId', { excludeId });