forked from wangziqi/gongxue-base
fix: resolve DingTalk dept ID to local department ID in class create
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user