feat: auto-populate department_id on create + seed default campus with backfill

This commit is contained in:
2026-07-06 00:05:00 +08:00
parent cd6364268d
commit df61ebbc5b
16 changed files with 130 additions and 23 deletions

View File

@@ -34,7 +34,9 @@ export class ClassroomsService {
async create(dto: CreateClassroomDto) {
const exists = await this.repo.findOne({ where: { name: dto.name } });
if (exists) throw new BadRequestException(`教室 ${dto.name} 已存在`);
return this.repo.save(this.repo.create(dto));
const entity = this.repo.create(dto);
if (dto.departmentId) entity.departmentId = dto.departmentId;
return this.repo.save(entity);
}
async update(id: number, dto: UpdateClassroomDto) {

View File

@@ -32,6 +32,10 @@ export class CreateClassroomDto {
@IsOptional()
@IsString()
notes?: string;
@IsOptional()
@IsInt()
departmentId?: number;
}
export class UpdateClassroomDto {