refactor: remove departmentId from Class entity

This commit is contained in:
2026-07-09 17:32:37 +08:00
parent 40fef906cd
commit 22bc1876d8
9 changed files with 4 additions and 116 deletions

View File

@@ -11,7 +11,6 @@ import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Department } from '../entities/department.entity';
import { Student } from '../entities/student.entity';
import { Class } from '../entities/class.entity';
import { StudentDingMapping } from '../entities/student-ding-mapping.entity';
// ── Types ──
@@ -189,8 +188,6 @@ export class DingTalkService {
private readonly studentRepo: Repository<Student>,
@InjectRepository(StudentDingMapping)
private readonly studentDingMappingRepo: Repository<StudentDingMapping>,
@InjectRepository(Class)
private readonly classRepo: Repository<Class>,
) {}
private get configured(): boolean {
@@ -381,26 +378,6 @@ export class DingTalkService {
}
await this.deptRepo.save(syncedDepts);
// ── Step 2.5: Auto-create Class for leaf departments ──
const parentIds = new Set(syncedDepts.map((d) => d.parentSourceId));
const leafDepts = syncedDepts.filter((d) => !parentIds.has(d.sourceId));
let classCreated = 0;
for (const leaf of leafDepts) {
const code = `DT_${leaf.sourceId}`;
const exists = await this.classRepo.findOne({ where: { code } });
if (!exists) {
const cls = this.classRepo.create({
name: leaf.name,
code,
departmentId: leaf.id,
classType: 'culture',
status: 'enrolling',
});
await this.classRepo.save(cls);
classCreated++;
}
}
if (classCreated > 0) this.logger.log(`从钉钉叶子部门自动创建 ${classCreated} 个班级`);
// ── Step 3: Sync users per department ──
let userCount = 0;