fix(server): remove CampusScope from AttendanceService
This commit is contained in:
@@ -6,7 +6,6 @@ import {
|
|||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository, In, Between, LessThanOrEqual, MoreThanOrEqual } from 'typeorm';
|
import { Repository, In, Between, LessThanOrEqual, MoreThanOrEqual } from 'typeorm';
|
||||||
import { AttendanceRecord, DingAttendanceRaw, Class, Student, ClassSchedule, ClassStudent, ScheduleType, UserDingMapping } from '../entities';
|
import { AttendanceRecord, DingAttendanceRaw, Class, Student, ClassSchedule, ClassStudent, ScheduleType, UserDingMapping } from '../entities';
|
||||||
import { CampusScope } from '../common/campus-scope';
|
|
||||||
import {
|
import {
|
||||||
BatchCreateAttendanceDto,
|
BatchCreateAttendanceDto,
|
||||||
AttendanceSummaryQueryDto,
|
AttendanceSummaryQueryDto,
|
||||||
@@ -34,9 +33,7 @@ export class AttendanceService {
|
|||||||
private scheduleRepo: Repository<ClassSchedule>,
|
private scheduleRepo: Repository<ClassSchedule>,
|
||||||
@InjectRepository(ClassStudent)
|
@InjectRepository(ClassStudent)
|
||||||
private classStudentRepo: Repository<ClassStudent>,
|
private classStudentRepo: Repository<ClassStudent>,
|
||||||
@InjectRepository(UserDingMapping)
|
|
||||||
private userDingMappingRepo: Repository<UserDingMapping>,
|
private userDingMappingRepo: Repository<UserDingMapping>,
|
||||||
private readonly scope: CampusScope,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
// ── Batch create attendance records ──
|
// ── Batch create attendance records ──
|
||||||
@@ -179,10 +176,6 @@ export class AttendanceService {
|
|||||||
// ── Attendance summary ──
|
// ── Attendance summary ──
|
||||||
async getSummary(query: AttendanceSummaryQueryDto) {
|
async getSummary(query: AttendanceSummaryQueryDto) {
|
||||||
const qb = this.attendanceRepo.createQueryBuilder('ar');
|
const qb = this.attendanceRepo.createQueryBuilder('ar');
|
||||||
const scopeIds = await this.scope.getScopeDepartmentIds();
|
|
||||||
if (scopeIds) {
|
|
||||||
qb.andWhere('ar.departmentId IN (:...scopeIds)', { scopeIds });
|
|
||||||
}
|
|
||||||
if (query.classId) {
|
if (query.classId) {
|
||||||
qb.andWhere('ar.classId = :classId', { classId: query.classId });
|
qb.andWhere('ar.classId = :classId', { classId: query.classId });
|
||||||
}
|
}
|
||||||
@@ -284,10 +277,6 @@ export class AttendanceService {
|
|||||||
const pageSize = query.pageSize || 20;
|
const pageSize = query.pageSize || 20;
|
||||||
|
|
||||||
const qb = this.attendanceRepo.createQueryBuilder('ar');
|
const qb = this.attendanceRepo.createQueryBuilder('ar');
|
||||||
const scopeIds = await this.scope.getScopeDepartmentIds();
|
|
||||||
if (scopeIds) {
|
|
||||||
qb.andWhere('ar.departmentId IN (:...scopeIds)', { scopeIds });
|
|
||||||
}
|
|
||||||
|
|
||||||
qb.leftJoinAndSelect('ar.student', 'student')
|
qb.leftJoinAndSelect('ar.student', 'student')
|
||||||
.leftJoinAndSelect('ar.class', 'class');
|
.leftJoinAndSelect('ar.class', 'class');
|
||||||
@@ -324,10 +313,6 @@ export class AttendanceService {
|
|||||||
.select('DISTINCT ar.classId', 'classId')
|
.select('DISTINCT ar.classId', 'classId')
|
||||||
.where('ar.classId IS NOT NULL');
|
.where('ar.classId IS NOT NULL');
|
||||||
|
|
||||||
const scopeIds = await this.scope.getScopeDepartmentIds();
|
|
||||||
if (scopeIds) {
|
|
||||||
qb.andWhere('ar.departmentId IN (:...scopeIds)', { scopeIds });
|
|
||||||
}
|
|
||||||
|
|
||||||
const rows = await qb
|
const rows = await qb
|
||||||
.orderBy('ar.classId', 'ASC')
|
.orderBy('ar.classId', 'ASC')
|
||||||
@@ -336,7 +321,7 @@ export class AttendanceService {
|
|||||||
const classIds = rows.map((r) => r.classId).filter(Boolean) as number[];
|
const classIds = rows.map((r) => r.classId).filter(Boolean) as number[];
|
||||||
if (classIds.length === 0) return [];
|
if (classIds.length === 0) return [];
|
||||||
|
|
||||||
const where = await this.scope.filter({ id: In(classIds) });
|
const where = { id: In(classIds) };
|
||||||
const classes = await this.classRepo.find({ where });
|
const classes = await this.classRepo.find({ where });
|
||||||
const nameMap = new Map(classes.map((c) => [c.id, c.name]));
|
const nameMap = new Map(classes.map((c) => [c.id, c.name]));
|
||||||
return classIds.map((id) => ({ classId: id, className: nameMap.get(id) || `班级${id}` }));
|
return classIds.map((id) => ({ classId: id, className: nameMap.get(id) || `班级${id}` }));
|
||||||
@@ -419,10 +404,6 @@ export class AttendanceService {
|
|||||||
source?: string;
|
source?: string;
|
||||||
}) {
|
}) {
|
||||||
const qb = this.attendanceRepo.createQueryBuilder('ar');
|
const qb = this.attendanceRepo.createQueryBuilder('ar');
|
||||||
const scopeIds = await this.scope.getScopeDepartmentIds();
|
|
||||||
if (scopeIds) {
|
|
||||||
qb.andWhere('ar.departmentId IN (:...scopeIds)', { scopeIds });
|
|
||||||
}
|
|
||||||
|
|
||||||
qb.leftJoinAndSelect('ar.student', 'student')
|
qb.leftJoinAndSelect('ar.student', 'student')
|
||||||
.leftJoinAndSelect('ar.class', 'class');
|
.leftJoinAndSelect('ar.class', 'class');
|
||||||
@@ -457,10 +438,6 @@ export class AttendanceService {
|
|||||||
throw new NotFoundException(`AttendanceRecord ${id} not found`);
|
throw new NotFoundException(`AttendanceRecord ${id} not found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const scopeIds = await this.scope.getScopeDepartmentIds();
|
|
||||||
if (scopeIds && !scopeIds.includes(record.departmentId)) {
|
|
||||||
throw new NotFoundException(`AttendanceRecord ${id} not found`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dto.status !== undefined) {
|
if (dto.status !== undefined) {
|
||||||
record.status = dto.status;
|
record.status = dto.status;
|
||||||
@@ -479,10 +456,6 @@ export class AttendanceService {
|
|||||||
throw new NotFoundException(`AttendanceRecord ${id} not found`);
|
throw new NotFoundException(`AttendanceRecord ${id} not found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const scopeIds = await this.scope.getScopeDepartmentIds();
|
|
||||||
if (scopeIds && !scopeIds.includes(record.departmentId)) {
|
|
||||||
throw new NotFoundException(`AttendanceRecord ${id} not found`);
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.attendanceRepo.remove(record);
|
await this.attendanceRepo.remove(record);
|
||||||
return { deleted: true };
|
return { deleted: true };
|
||||||
@@ -491,10 +464,6 @@ export class AttendanceService {
|
|||||||
// ── Class-based attendance report ──
|
// ── Class-based attendance report ──
|
||||||
async getReport(query: AttendanceReportQueryDto) {
|
async getReport(query: AttendanceReportQueryDto) {
|
||||||
const qb = this.attendanceRepo.createQueryBuilder('ar');
|
const qb = this.attendanceRepo.createQueryBuilder('ar');
|
||||||
const scopeIds = await this.scope.getScopeDepartmentIds();
|
|
||||||
if (scopeIds) {
|
|
||||||
qb.andWhere('ar.departmentId IN (:...scopeIds)', { scopeIds });
|
|
||||||
}
|
|
||||||
|
|
||||||
qb.leftJoin('ar.class', 'class')
|
qb.leftJoin('ar.class', 'class')
|
||||||
.select('class.id', 'classId')
|
.select('class.id', 'classId')
|
||||||
@@ -567,10 +536,6 @@ export class AttendanceService {
|
|||||||
.leftJoinAndSelect('a.student', 'student')
|
.leftJoinAndSelect('a.student', 'student')
|
||||||
.leftJoinAndSelect('a.class', 'class');
|
.leftJoinAndSelect('a.class', 'class');
|
||||||
|
|
||||||
const scopeIds = await this.scope.getScopeDepartmentIds();
|
|
||||||
if (scopeIds) {
|
|
||||||
qb.andWhere('a.departmentId IN (:...scopeIds)', { scopeIds });
|
|
||||||
}
|
|
||||||
|
|
||||||
const records = await qb
|
const records = await qb
|
||||||
.where('a.attendanceDate >= :cutoff', { cutoff: cutoffStr })
|
.where('a.attendanceDate >= :cutoff', { cutoff: cutoffStr })
|
||||||
|
|||||||
Reference in New Issue
Block a user