feat(attendance): add single-record edit and delete APIs

- Add PUT /attendance-records/:id to update status and remark
- Add DELETE /attendance-records/:id to remove a record
- Enforce campus scope on both operations
- Log edit/delete actions via OperationLogsService
This commit is contained in:
2026-07-06 17:39:16 +08:00
parent 85872d6564
commit ba34c09be4
3 changed files with 100 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ import {
QueryDingRawDto,
MatchDingRecordDto,
AttendanceReportQueryDto,
UpdateAttendanceRecordDto,
} from './dto/attendance.dto';
@Injectable()
@@ -314,6 +315,44 @@ export class AttendanceService {
return qb.getMany();
}
// ── Update a single attendance record ──
async update(id: number, dto: UpdateAttendanceRecordDto) {
const record = await this.attendanceRepo.findOne({ where: { id } });
if (!record) {
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) {
record.status = dto.status;
}
if (dto.remark !== undefined) {
record.remark = dto.remark;
}
return this.attendanceRepo.save(record);
}
// ── Delete a single attendance record ──
async remove(id: number) {
const record = await this.attendanceRepo.findOne({ where: { id } });
if (!record) {
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);
return { deleted: true };
}
// ── Class-based attendance report ──
async getReport(query: AttendanceReportQueryDto) {
const qb = this.attendanceRepo.createQueryBuilder('ar');