refactor: remove User-based import and RBAC UserDingMapping endpoints

This commit is contained in:
2026-07-09 17:10:33 +08:00
parent 570ef7b7e9
commit 7b8691866e
7 changed files with 8 additions and 844 deletions

View File

@@ -1,4 +1,4 @@
import { IsString, MinLength, IsOptional, IsArray, IsBoolean, IsInt, IsNotEmpty } from 'class-validator';
import { IsString, MinLength, IsOptional, IsArray, IsBoolean } from 'class-validator';
export class CreateRoleDto {
@IsString()
@@ -80,12 +80,3 @@ export class UpdateProfileDto {
qualifications?: string;
}
export class CreateStudentDingMappingDto {
@IsInt()
@IsNotEmpty()
studentId: number;
@IsString()
@IsNotEmpty()
dingUserId: string;
}

View File

@@ -19,7 +19,6 @@ import {
UpdateUserDto,
ResetPasswordDto,
UpdateProfileDto,
CreateStudentDingMappingDto,
} from './dto/rbac.dto';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { RequirePermission } from '../auth/decorators/permission.decorator';
@@ -299,32 +298,6 @@ export class RbacController {
}
}
// ---- 钉钉用户绑定 ----
@Get('user-ding-mappings')
@RequirePermission('user:view')
async getStudentDingMappings() {
return this.rbacService.getUserDingMappings();
}
@Get('user-ding-mappings/unbound-users')
@RequirePermission('user:view')
async getUnboundUsers() {
return this.rbacService.getUnboundUsers();
}
@Post('user-ding-mappings')
@RequirePermission('user:edit')
async createStudentDingMapping(@Body() dto: CreateStudentDingMappingDto) {
return this.rbacService.createUserDingMapping(dto);
}
@Delete('user-ding-mappings/:id')
@RequirePermission('user:delete')
async deleteStudentDingMapping(@Param('id') id: string) {
return this.rbacService.deleteUserDingMapping(+id);
}
// ---- 教师工作台 ----
@Get('teacher-workspace')

View File

@@ -1,8 +1,8 @@
import { Injectable, Logger, NotFoundException, ConflictException } from '@nestjs/common';
import { Injectable, Logger, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, In } from 'typeorm';
import * as bcrypt from 'bcryptjs';
import { Permission, Role, User, Class, ClassStudent, ClassTeacher, ClassSchedule, Student, StudentDingMapping } from '../entities';
import { Permission, Role, User, Class, ClassStudent, ClassTeacher, ClassSchedule, Student } from '../entities';
const PRESET_PERMISSIONS: Array<{ code: string; name: string; group: string }> = [
{ code: 'dashboard:view', name: '查看数据面板', group: 'dashboard' },
@@ -171,7 +171,6 @@ export class RbacService {
@InjectRepository(ClassTeacher) private classTeacherRepo: Repository<ClassTeacher>,
@InjectRepository(ClassSchedule) private classScheduleRepo: Repository<ClassSchedule>,
@InjectRepository(Student) private studentRepo: Repository<Student>,
@InjectRepository(StudentDingMapping) private mappingRepo: Repository<StudentDingMapping>,
) {}
async seedData(): Promise<void> {
@@ -247,32 +246,6 @@ export class RbacService {
this.logger.log(`种子数据初始化完成: ${allPerms.length} 权限点, ${allRoles.length} 角色`);
}
// ---- 钉钉用户绑定 ----
async getUserDingMappings(): Promise<StudentDingMapping[]> {
return this.mappingRepo.find({ relations: ['student'] });
}
async createUserDingMapping(dto: { studentId: number; dingUserId: string }) {
const existing = await this.mappingRepo.findOne({ where: { dingUserId: dto.dingUserId } });
if (existing) throw new ConflictException(`钉钉用户 ${dto.dingUserId} 已绑定到学生 #${existing.studentId}`);
const studentExisting = await this.mappingRepo.findOne({ where: { studentId: dto.studentId } });
if (studentExisting) throw new ConflictException(`学生 #${dto.studentId} 已绑定到钉钉用户 ${studentExisting.dingUserId}`);
const mapping = this.mappingRepo.create(dto);
return this.mappingRepo.save(mapping);
}
async deleteUserDingMapping(id: number) {
const mapping = await this.mappingRepo.findOne({ where: { id } });
if (!mapping) throw new NotFoundException('绑定记录不存在');
await this.mappingRepo.remove(mapping);
return { success: true };
}
// ponytail: StudentDingMapping.studentId is Student FK, not User; method deleted in Task 4
async getUnboundUsers(): Promise<{ id: number; username: string; name: string }[]> {
return [];
}
async findAllRoles(): Promise<Role[]> {
return this.roleRepo.find({