feat: auto-populate department_id on create + seed default campus with backfill
This commit is contained in:
@@ -60,6 +60,10 @@ export class CreateScheduleDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
notes?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
departmentId?: number;
|
||||
}
|
||||
|
||||
export class UpdateScheduleDto {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable, NotFoundException, ConflictException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { ClassSchedule } from '../entities';
|
||||
import { ClassSchedule, Class } from '../entities';
|
||||
import { CampusScope } from '../common/campus-scope';
|
||||
import {
|
||||
CreateScheduleDto,
|
||||
@@ -16,6 +16,7 @@ export class SchedulesService {
|
||||
@InjectRepository(ClassSchedule)
|
||||
private readonly scheduleRepo: Repository<ClassSchedule>,
|
||||
private readonly scope: CampusScope,
|
||||
@InjectRepository(Class) private readonly classRepo: Repository<Class>,
|
||||
) {}
|
||||
|
||||
async findAll(query: QueryScheduleDto) {
|
||||
@@ -47,6 +48,12 @@ export class SchedulesService {
|
||||
await this.checkConflict(dto.classroomId, dto.weekDay, dto.startTime, dto.endTime, dto.startDate, dto.endDate);
|
||||
|
||||
const schedule = this.scheduleRepo.create(dto);
|
||||
if (dto.departmentId) {
|
||||
schedule.departmentId = dto.departmentId;
|
||||
} else if (dto.classId) {
|
||||
const cls = await this.classRepo.findOne({ where: { id: dto.classId } });
|
||||
if (cls) schedule.departmentId = cls.departmentId;
|
||||
}
|
||||
const saved = await this.scheduleRepo.save(schedule);
|
||||
return this.findOne(saved.id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user