From 40fef906cdf67248fc98f1cf63ef216caead1d96 Mon Sep 17 00:00:00 2001 From: wangziqi Date: Thu, 9 Jul 2026 17:28:12 +0800 Subject: [PATCH] fix: resolve DingTalk dept ID to local department ID in class create --- apps/server/src/classes/classes.service.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/apps/server/src/classes/classes.service.ts b/apps/server/src/classes/classes.service.ts index 89b3799..c69c0f1 100644 --- a/apps/server/src/classes/classes.service.ts +++ b/apps/server/src/classes/classes.service.ts @@ -99,6 +99,22 @@ export class ClassesService { async create(dto: CreateClassDto) { const { studentIds, teachers, dingUserIds, ...classData } = dto; + // Resolve departmentId: frontend may pass DingTalk dept ID, map to local + if (classData.departmentId) { + const localDept = await this.deptRepo.findOne({ + where: { source: 'dingtalk', sourceId: String(classData.departmentId) }, + }); + if (localDept) { + classData.departmentId = localDept.id; + } else { + // Verify it's a valid local department ID + const exists = await this.deptRepo.findOne({ where: { id: classData.departmentId } }); + if (!exists) { + throw new BadRequestException(`部门 ID ${classData.departmentId} 不存在`); + } + } + } + const cls = this.classRepo.create(classData); const saved = await this.classRepo.save(cls);