forked from wangziqi/gongxue-base
feat: integrate CampusScope.filter() into all business services (12 services + 12 modules)
This commit is contained in:
@@ -3,6 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository, In, Like } from 'typeorm';
|
||||
import { Class, ClassStudent, ClassTeacher } from '../entities';
|
||||
import { CreateClassDto, UpdateClassDto, QueryClassDto, AddTeacherDto } from './dto/class.dto';
|
||||
import { CampusScope } from '../common/campus-scope';
|
||||
|
||||
interface RawStudentCount {
|
||||
classId: string;
|
||||
@@ -18,14 +19,16 @@ export class ClassesService {
|
||||
private classStudentRepo: Repository<ClassStudent>,
|
||||
@InjectRepository(ClassTeacher)
|
||||
private classTeacherRepo: Repository<ClassTeacher>,
|
||||
private readonly scope: CampusScope,
|
||||
) {}
|
||||
|
||||
async findAll(query: QueryClassDto) {
|
||||
const where: Record<string, unknown> = {};
|
||||
let where: Record<string, unknown> = {};
|
||||
if (query.departmentId) where.departmentId = query.departmentId;
|
||||
if (query.status) where.status = query.status;
|
||||
if (query.classType) where.classType = query.classType;
|
||||
if (query.keyword) where.name = Like(`%${query.keyword}%`);
|
||||
where = await this.scope.filter(where);
|
||||
|
||||
const classes = await this.classRepo.find({
|
||||
where,
|
||||
|
||||
Reference in New Issue
Block a user