diff --git a/apps/server/src/students/students.controller.ts b/apps/server/src/students/students.controller.ts index db52d78..bf82132 100644 --- a/apps/server/src/students/students.controller.ts +++ b/apps/server/src/students/students.controller.ts @@ -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') diff --git a/apps/server/src/students/students.service.ts b/apps/server/src/students/students.service.ts index 11d91a2..554b2a6 100644 --- a/apps/server/src/students/students.service.ts +++ b/apps/server/src/students/students.service.ts @@ -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 = {}; 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) {