feat: integrate CampusScope.filter() into all business services (12 services + 12 modules)
This commit is contained in:
@@ -15,6 +15,7 @@ import { Student } from '../entities/student.entity';
|
||||
import { Deposit } from '../entities/deposit.entity';
|
||||
import { CheckInDto, CheckOutDto, TransferRoomDto } from './dto/occupancy.dto';
|
||||
import { RoomsService } from '../rooms/rooms.service';
|
||||
import { CampusScope } from '../common/campus-scope';
|
||||
|
||||
@Injectable()
|
||||
export class OccupanciesService {
|
||||
@@ -24,6 +25,7 @@ export class OccupanciesService {
|
||||
@InjectRepository(Student) private studentRepo: Repository<Student>,
|
||||
@InjectRepository(Deposit) private depositRepo: Repository<Deposit>,
|
||||
private dataSource: DataSource,
|
||||
private readonly scope: CampusScope,
|
||||
) {}
|
||||
|
||||
async findAll(query?: { roomId?: number; studentId?: number; active?: boolean }) {
|
||||
@@ -32,6 +34,10 @@ export class OccupanciesService {
|
||||
.leftJoinAndSelect('o.student', 'student')
|
||||
.leftJoinAndSelect('o.room', 'room')
|
||||
.orderBy('o.checkInDate', 'DESC');
|
||||
const scopeIds = await this.scope.getScopeDepartmentIds();
|
||||
if (scopeIds) {
|
||||
qb.andWhere('o.departmentId IN (:...scopeIds)', { scopeIds });
|
||||
}
|
||||
if (query?.roomId) qb.andWhere('o.roomId = :roomId', { roomId: query.roomId });
|
||||
if (query?.studentId) qb.andWhere('o.studentId = :studentId', { studentId: query.studentId });
|
||||
if (query?.active) qb.andWhere('o.checkOutDate IS NULL');
|
||||
|
||||
Reference in New Issue
Block a user