forked from wangziqi/gongxue-base
fix: review blockers — entity registration, session enum, conflict date-range, @Type decorators
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user