Task 4: 学生列表 tenantId 筛选生效

- StudentsService.findAll() 接收 tenantId 参数并按 tenantId 过滤
- StudentsController.findAll() 增加 tenantId 查询参数
- students.organization 列仍在 occupancy/room-visual/import 等场景使用,未删除列
This commit is contained in:
2026-07-06 17:39:24 +08:00
parent ba34c09be4
commit 3fa446f978
2 changed files with 11 additions and 4 deletions

View File

@@ -43,8 +43,14 @@ export class StudentsController {
@Query('name') name?: string,
@Query('status') status?: string,
@Query('includeArchived') includeArchived?: string,
@Query('tenantId') tenantId?: string,
) {
return this.service.findAll({ name, status, includeArchived: includeArchived === 'true' });
return this.service.findAll({
name,
status,
includeArchived: includeArchived === 'true',
tenantId: tenantId ? +tenantId : undefined,
});
}
@Get('export')

View File

@@ -1,6 +1,6 @@
import { Injectable, NotFoundException, BadRequestException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, Like, Not, In } from 'typeorm';
import { Repository, Like, Not, In, FindOptionsWhere } from 'typeorm';
import { CampusScope } from '../common/campus-scope';
import { Student } from '../entities/student.entity';
import { Class } from '../entities/class.entity';
@@ -19,9 +19,10 @@ export class StudentsService {
private readonly scope: CampusScope,
) {}
async findAll(query?: { name?: string; status?: string; includeArchived?: boolean }) {
const where: any = {};
async findAll(query?: { name?: string; status?: string; includeArchived?: boolean; tenantId?: number | string }) {
const where: FindOptionsWhere<Student> = {};
if (query?.name) where.name = Like(`%${query.name}%`);
if (query?.tenantId) where.tenantId = Number(query.tenantId);
if (query?.status) {
where.status = query.status;
} else if (!query?.includeArchived) {