fix: correct studentId-as-userId bugs in 3 files
- dingtalk.service.ts syncOneUser: find Student by userId before mapping, use Student.id (not User.id) as studentId FK - sync.service.ts importDingTalkUsers: type coercion for studentId (method deleted in Task 4, minimal compile fix) - schedule-sync.service.ts getStatus: remove broken teacher mapping query (teacher scheduling deprecated); hardcode mappedTeachers=0, totalTeachers=0
This commit is contained in:
@@ -663,12 +663,13 @@ export class DingTalkService {
|
||||
}
|
||||
}
|
||||
|
||||
// Create mapping
|
||||
// ponytail: find student by userId — method rewritten in Task 2
|
||||
const student = await this.studentRepo.findOne({ where: { userId: user.id } });
|
||||
if (!student) return;
|
||||
mapping = this.studentDingMappingRepo.create({
|
||||
dingUserId: du.userid,
|
||||
studentId: user.id,
|
||||
studentId: student.id,
|
||||
});
|
||||
await this.studentDingMappingRepo.save(mapping);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository, In, Not, IsNull } from 'typeorm';
|
||||
import { Repository, Not, IsNull } from 'typeorm';
|
||||
import {
|
||||
ClassSchedule,
|
||||
StudentDingMapping,
|
||||
ClassStudent,
|
||||
ClassTeacher,
|
||||
Department,
|
||||
@@ -47,8 +46,6 @@ export class ScheduleSyncService {
|
||||
constructor(
|
||||
@InjectRepository(ClassSchedule)
|
||||
private readonly scheduleRepo: Repository<ClassSchedule>,
|
||||
@InjectRepository(StudentDingMapping)
|
||||
private readonly studentDingMappingRepo: Repository<StudentDingMapping>,
|
||||
@InjectRepository(ClassTeacher)
|
||||
private readonly classTeacherRepo: Repository<ClassTeacher>,
|
||||
@InjectRepository(Department)
|
||||
@@ -279,19 +276,16 @@ export class ScheduleSyncService {
|
||||
return d.toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
/** 获取排班同步状态:活跃排课数量 + 有钉钉映射的教师数 */
|
||||
async getStatus(targetDate: string): Promise<{ activeSchedules: number; mappedTeachers: number; totalTeachers: number }> {
|
||||
/** 获取排班同步状态:活跃排课数量 */
|
||||
async getStatus(_targetDate: string): Promise<{ activeSchedules: number; mappedTeachers: number; totalTeachers: number }> {
|
||||
const schedules = await this.scheduleRepo.find({
|
||||
where: { status: 'active', teacherId: Not(IsNull()) },
|
||||
});
|
||||
const teacherIds = [...new Set(schedules.map((s) => s.teacherId!).filter(Boolean))];
|
||||
const mappings = await this.studentDingMappingRepo.find({
|
||||
where: { studentId: In(teacherIds) },
|
||||
});
|
||||
// ponytail: teacher scheduling is deprecated; mappedTeachers always 0
|
||||
return {
|
||||
activeSchedules: schedules.length,
|
||||
mappedTeachers: mappings.length,
|
||||
totalTeachers: teacherIds.length,
|
||||
mappedTeachers: 0,
|
||||
totalTeachers: 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ export class SyncService {
|
||||
if (!existingMappingForUser) {
|
||||
const mapping = manager.create(StudentDingMapping, {
|
||||
dingUserId: u.dingUserId,
|
||||
studentId: user.id,
|
||||
studentId: (user as any).id,
|
||||
});
|
||||
await manager.save(mapping);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user