refactor: replace UserDingMapping with StudentDingMapping entity
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* 提供:
|
||||
* - OAuth2 access_token(新版 API + 缓存)
|
||||
* - BFS 遍历所有部门 + 用户(带限流)
|
||||
* - 用户同步(自动建 User + Student + UserDingMapping)
|
||||
* - 用户同步(自动建 User + Student + StudentDingMapping)
|
||||
*/
|
||||
import { Injectable, Logger, ServiceUnavailableException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
@@ -14,7 +14,7 @@ import { Department } from '../entities/department.entity';
|
||||
import { User } from '../entities/user.entity';
|
||||
import { Student } from '../entities/student.entity';
|
||||
import { Class } from '../entities/class.entity';
|
||||
import { UserDingMapping } from '../entities/user-ding-mapping.entity';
|
||||
import { StudentDingMapping } from '../entities/student-ding-mapping.entity';
|
||||
|
||||
// ── Types ──
|
||||
|
||||
@@ -191,8 +191,8 @@ export class DingTalkService {
|
||||
private readonly userRepo: Repository<User>,
|
||||
@InjectRepository(Student)
|
||||
private readonly studentRepo: Repository<Student>,
|
||||
@InjectRepository(UserDingMapping)
|
||||
private readonly mappingRepo: Repository<UserDingMapping>,
|
||||
@InjectRepository(StudentDingMapping)
|
||||
private readonly studentDingMappingRepo: Repository<StudentDingMapping>,
|
||||
@InjectRepository(Class)
|
||||
private readonly classRepo: Repository<Class>,
|
||||
) {}
|
||||
@@ -608,18 +608,16 @@ export class DingTalkService {
|
||||
mobile: string;
|
||||
}): Promise<void> {
|
||||
// Look up by mapping first
|
||||
let mapping = await this.mappingRepo.findOne({ where: { dingUserId: du.userid } });
|
||||
let mapping = await this.studentDingMappingRepo.findOne({ where: { dingUserId: du.userid } });
|
||||
let user: User | null = null;
|
||||
|
||||
if (mapping) {
|
||||
user = await this.userRepo.findOne({ where: { id: mapping.userId } });
|
||||
user = await this.userRepo.findOne({ where: { id: mapping.studentId } });
|
||||
if (user) {
|
||||
user.name = du.name;
|
||||
await this.userRepo.save(user);
|
||||
}
|
||||
mapping.dingName = du.name;
|
||||
mapping.dingMobile = du.mobile;
|
||||
await this.mappingRepo.save(mapping);
|
||||
await this.studentDingMappingRepo.save(mapping);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -666,13 +664,11 @@ export class DingTalkService {
|
||||
}
|
||||
|
||||
// Create mapping
|
||||
mapping = this.mappingRepo.create({
|
||||
mapping = this.studentDingMappingRepo.create({
|
||||
dingUserId: du.userid,
|
||||
userId: user.id,
|
||||
dingName: du.name,
|
||||
dingMobile: du.mobile,
|
||||
studentId: user.id,
|
||||
});
|
||||
await this.mappingRepo.save(mapping);
|
||||
await this.studentDingMappingRepo.save(mapping);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Department, User, Student, UserDingMapping, Class } from '../entities';
|
||||
import { Department, User, Student, StudentDingMapping, Class } from '../entities';
|
||||
import { DingTalkService } from './dingtalk.service';
|
||||
import { WeComService } from './wecom.service';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Department, User, Student, UserDingMapping, Class])],
|
||||
imports: [TypeOrmModule.forFeature([Department, User, Student, StudentDingMapping, Class])],
|
||||
providers: [DingTalkService, WeComService],
|
||||
exports: [DingTalkService, WeComService],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user