joinDate/leaveDate/checkInDate/sync 起始日等业务日期默认值原来用 dayjs().utc()(UTC 今天),在国内 00:00-07:59 会取到昨天。 统一改为 dayjs().utcOffset(8)(固定 UTC+8 中国日期),与考勤周边界 修复保持一致;pending-tasks/controller-base 的本地 dayjs() 也显式化。
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import { UseGuards } from '@nestjs/common';
|
|
import dayjs from '../common/dayjs';
|
|
import { AttendanceService } from './attendance.service';
|
|
import { AttendanceImportService } from './attendance-import.service';
|
|
import { OperationLogsService } from '../operation-logs/operation-logs.service';
|
|
import { AuthorizationService, CaslAction, SubjectName } from '../authorization';
|
|
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
|
|
|
/** Minimal request user shape for type safety */
|
|
export interface RequestUser {
|
|
id: number;
|
|
username: string;
|
|
permissions: string[];
|
|
isSuperAdmin: boolean;
|
|
roles: string[];
|
|
}
|
|
|
|
/** SSE event shape for @Sse() decorator */
|
|
export interface SseEvent {
|
|
data: string | Record<string, unknown>;
|
|
id?: string;
|
|
type?: string;
|
|
retry?: number;
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
export abstract class AttendanceControllerBase {
|
|
constructor(
|
|
protected readonly service: AttendanceService,
|
|
protected readonly importService: AttendanceImportService,
|
|
protected readonly logService: OperationLogsService,
|
|
protected readonly authz: AuthorizationService,
|
|
) {}
|
|
|
|
protected getTodayDateOnly(): string {
|
|
return dayjs().utcOffset(8).format('YYYY-MM-DD');
|
|
}
|
|
|
|
protected canManageAllAttendance(req: { user: RequestUser }): boolean {
|
|
return (
|
|
this.authz.can(req, CaslAction.Manage, SubjectName.Attendance) ||
|
|
// Legacy: class:edit grants broad attendance access for teacher scoping
|
|
this.authz.can(req, CaslAction.Update, SubjectName.Class)
|
|
);
|
|
}
|
|
|
|
protected getAccessibleClassIds(req: { user: RequestUser }) {
|
|
return this.service.getAccessibleClassIds(req.user.id, this.canManageAllAttendance(req));
|
|
}
|
|
|
|
protected assertClassAccess(req: { user: RequestUser }, classId: number) {
|
|
return this.service.assertClassAccess(req.user.id, classId, this.canManageAllAttendance(req));
|
|
}
|
|
}
|