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, ClassroomRental,
Permission, Permission,
Role, Role,
Class,
ClassStudent,
ClassTeacher,
ClassSchedule, ClassSchedule,
AttendanceRecord, AttendanceRecord,
DingAttendanceRaw, DingAttendanceRaw,

View File

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

View File

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

View File

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

View File

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