refactor: remove departmentId from Class entity
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user