feat: integrate CampusScope.filter() into all business services (12 services + 12 modules)

This commit is contained in:
2026-07-05 23:58:51 +08:00
parent eeae06fe30
commit cd6364268d
40 changed files with 949 additions and 172 deletions

View File

@@ -1,6 +1,7 @@
import { Injectable, NotFoundException, BadRequestException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, Like, Not, In } from 'typeorm';
import { CampusScope } from '../common/campus-scope';
import { Student } from '../entities/student.entity';
import { ClassStudent } from '../entities/class-student.entity';
import { AttendanceRecord } from '../entities/attendance-record.entity';
@@ -13,6 +14,7 @@ export class StudentsService {
@InjectRepository(Student) private repo: Repository<Student>,
@InjectRepository(ClassStudent) private classStudentRepo: Repository<ClassStudent>,
@InjectRepository(AttendanceRecord) private attendanceRepo: Repository<AttendanceRecord>,
private readonly scope: CampusScope,
) {}
async findAll(query?: { name?: string; status?: string; includeArchived?: boolean }) {
@@ -23,7 +25,8 @@ export class StudentsService {
} else if (!query?.includeArchived) {
where.status = Not('archived');
}
return this.repo.find({ where, order: { createdAt: 'DESC' } });
const filteredWhere = await this.scope.filter(where);
return this.repo.find({ where: filteredWhere, order: { createdAt: 'DESC' }, relations: ['tenant'] });
}
async findOne(id: number) {
@@ -101,6 +104,7 @@ export class StudentsService {
emergencyPhone?: string;
organization?: string;
supervisor?: string;
tenantId?: number;
}[],
) {
let imported = 0;
@@ -126,9 +130,9 @@ export class StudentsService {
emergencyPhone: row.emergencyPhone || undefined,
organization: row.organization || undefined,
supervisor: row.supervisor || undefined,
tenantId: row.tenantId || undefined,
}),
);
imported++;
}
return {
message: `成功导入 ${imported} 名学生,跳过 ${skipped} 条(重复或空行)`,