From 7f355952fda153dcc21c67d469675960a0e3accc Mon Sep 17 00:00:00 2001 From: wangziqi Date: Thu, 9 Jul 2026 15:29:50 +0800 Subject: [PATCH] fix(server): remove CampusScope from AttendanceService --- .../src/attendance/attendance.service.ts | 37 +------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/apps/server/src/attendance/attendance.service.ts b/apps/server/src/attendance/attendance.service.ts index fba132c..2a3630a 100644 --- a/apps/server/src/attendance/attendance.service.ts +++ b/apps/server/src/attendance/attendance.service.ts @@ -6,7 +6,6 @@ import { import { InjectRepository } from '@nestjs/typeorm'; import { Repository, In, Between, LessThanOrEqual, MoreThanOrEqual } from 'typeorm'; import { AttendanceRecord, DingAttendanceRaw, Class, Student, ClassSchedule, ClassStudent, ScheduleType, UserDingMapping } from '../entities'; -import { CampusScope } from '../common/campus-scope'; import { BatchCreateAttendanceDto, AttendanceSummaryQueryDto, @@ -34,9 +33,7 @@ export class AttendanceService { private scheduleRepo: Repository, @InjectRepository(ClassStudent) private classStudentRepo: Repository, - @InjectRepository(UserDingMapping) private userDingMappingRepo: Repository, - private readonly scope: CampusScope, ) {} // ── Batch create attendance records ── @@ -179,10 +176,6 @@ export class AttendanceService { // ── Attendance summary ── async getSummary(query: AttendanceSummaryQueryDto) { const qb = this.attendanceRepo.createQueryBuilder('ar'); - const scopeIds = await this.scope.getScopeDepartmentIds(); - if (scopeIds) { - qb.andWhere('ar.departmentId IN (:...scopeIds)', { scopeIds }); - } if (query.classId) { qb.andWhere('ar.classId = :classId', { classId: query.classId }); } @@ -284,10 +277,6 @@ export class AttendanceService { const pageSize = query.pageSize || 20; const qb = this.attendanceRepo.createQueryBuilder('ar'); - const scopeIds = await this.scope.getScopeDepartmentIds(); - if (scopeIds) { - qb.andWhere('ar.departmentId IN (:...scopeIds)', { scopeIds }); - } qb.leftJoinAndSelect('ar.student', 'student') .leftJoinAndSelect('ar.class', 'class'); @@ -324,10 +313,6 @@ export class AttendanceService { .select('DISTINCT ar.classId', 'classId') .where('ar.classId IS NOT NULL'); - const scopeIds = await this.scope.getScopeDepartmentIds(); - if (scopeIds) { - qb.andWhere('ar.departmentId IN (:...scopeIds)', { scopeIds }); - } const rows = await qb .orderBy('ar.classId', 'ASC') @@ -336,7 +321,7 @@ export class AttendanceService { const classIds = rows.map((r) => r.classId).filter(Boolean) as number[]; if (classIds.length === 0) return []; - const where = await this.scope.filter({ id: In(classIds) }); + const where = { id: In(classIds) }; const classes = await this.classRepo.find({ where }); const nameMap = new Map(classes.map((c) => [c.id, c.name])); return classIds.map((id) => ({ classId: id, className: nameMap.get(id) || `班级${id}` })); @@ -419,10 +404,6 @@ export class AttendanceService { source?: string; }) { const qb = this.attendanceRepo.createQueryBuilder('ar'); - const scopeIds = await this.scope.getScopeDepartmentIds(); - if (scopeIds) { - qb.andWhere('ar.departmentId IN (:...scopeIds)', { scopeIds }); - } qb.leftJoinAndSelect('ar.student', 'student') .leftJoinAndSelect('ar.class', 'class'); @@ -457,10 +438,6 @@ export class AttendanceService { throw new NotFoundException(`AttendanceRecord ${id} not found`); } - const scopeIds = await this.scope.getScopeDepartmentIds(); - if (scopeIds && !scopeIds.includes(record.departmentId)) { - throw new NotFoundException(`AttendanceRecord ${id} not found`); - } if (dto.status !== undefined) { record.status = dto.status; @@ -479,10 +456,6 @@ export class AttendanceService { throw new NotFoundException(`AttendanceRecord ${id} not found`); } - const scopeIds = await this.scope.getScopeDepartmentIds(); - if (scopeIds && !scopeIds.includes(record.departmentId)) { - throw new NotFoundException(`AttendanceRecord ${id} not found`); - } await this.attendanceRepo.remove(record); return { deleted: true }; @@ -491,10 +464,6 @@ export class AttendanceService { // ── Class-based attendance report ── async getReport(query: AttendanceReportQueryDto) { const qb = this.attendanceRepo.createQueryBuilder('ar'); - const scopeIds = await this.scope.getScopeDepartmentIds(); - if (scopeIds) { - qb.andWhere('ar.departmentId IN (:...scopeIds)', { scopeIds }); - } qb.leftJoin('ar.class', 'class') .select('class.id', 'classId') @@ -567,10 +536,6 @@ export class AttendanceService { .leftJoinAndSelect('a.student', 'student') .leftJoinAndSelect('a.class', 'class'); - const scopeIds = await this.scope.getScopeDepartmentIds(); - if (scopeIds) { - qb.andWhere('a.departmentId IN (:...scopeIds)', { scopeIds }); - } const records = await qb .where('a.attendanceDate >= :cutoff', { cutoff: cutoffStr })