refactor: resolve remaining field audit issues

This commit is contained in:
2026-07-13 15:12:36 +08:00
parent 0533c30ece
commit aa1ed7db56
34 changed files with 953 additions and 263 deletions

View File

@@ -15,8 +15,11 @@ import { ArchiveAttachment } from '../entities/archive-attachment.entity';
import {
UpsertProfileDto,
CreateEnrollmentDto,
UpdateEnrollmentDto,
CreateExamScoreDto,
UpdateExamScoreDto,
CreateLearningRecordDto,
UpdateLearningRecordDto,
UpsertResultDto,
} from './dto/archive.dto';
@@ -44,7 +47,9 @@ export class ArchiveService {
? path.resolve(process.cwd(), normalizedPath)
: path.resolve(this.uploadDir, normalizedPath);
const allowedRoots = [this.uploadDir, path.resolve(process.cwd(), 'uploads', 'archive')];
if (!allowedRoots.some((root) => fullPath === root || fullPath.startsWith(`${root}${path.sep}`))) {
if (
!allowedRoots.some((root) => fullPath === root || fullPath.startsWith(`${root}${path.sep}`))
) {
throw new BadRequestException('路径非法');
}
return fullPath;
@@ -54,21 +59,15 @@ export class ArchiveService {
const student = await this.studentRepo.findOne({ where: { id: studentId } });
if (!student) throw new NotFoundException('学生不存在');
const [
profileRaw,
enrollments,
examScores,
learningRecords,
resultArchive,
attachments,
] = await Promise.all([
this.profileRepo.findOne({ where: { studentId } }),
this.enrollmentRepo.find({ where: { studentId }, order: { createdAt: 'DESC' } }),
this.examScoreRepo.find({ where: { studentId }, order: { examDate: 'DESC' } }),
this.learningRecordRepo.find({ where: { studentId }, order: { recordDate: 'DESC' } }),
this.resultRepo.findOne({ where: { studentId } }),
this.attachmentRepo.find({ where: { studentId }, order: { createdAt: 'DESC' } }),
]);
const [profileRaw, enrollments, examScores, learningRecords, resultArchive, attachments] =
await Promise.all([
this.profileRepo.findOne({ where: { studentId } }),
this.enrollmentRepo.find({ where: { studentId }, order: { createdAt: 'DESC' } }),
this.examScoreRepo.find({ where: { studentId }, order: { examDate: 'DESC' } }),
this.learningRecordRepo.find({ where: { studentId }, order: { recordDate: 'DESC' } }),
this.resultRepo.findOne({ where: { studentId } }),
this.attachmentRepo.find({ where: { studentId }, order: { createdAt: 'DESC' } }),
]);
return {
student,
@@ -102,7 +101,7 @@ export class ArchiveService {
return this.enrollmentRepo.save(entity);
}
async updateEnrollment(id: number, dto: Partial<CreateEnrollmentDto>) {
async updateEnrollment(id: number, dto: UpdateEnrollmentDto) {
const entity = await this.enrollmentRepo.findOne({ where: { id } });
if (!entity) throw new NotFoundException('报名记录不存在');
Object.assign(entity, dto);
@@ -124,7 +123,7 @@ export class ArchiveService {
return this.examScoreRepo.save(entity);
}
async updateExamScore(id: number, dto: Partial<CreateExamScoreDto>) {
async updateExamScore(id: number, dto: UpdateExamScoreDto) {
const entity = await this.examScoreRepo.findOne({ where: { id } });
if (!entity) throw new NotFoundException('考试成绩不存在');
Object.assign(entity, dto);
@@ -146,7 +145,7 @@ export class ArchiveService {
return this.learningRecordRepo.save(entity);
}
async updateLearningRecord(id: number, dto: Partial<CreateLearningRecordDto>) {
async updateLearningRecord(id: number, dto: UpdateLearningRecordDto) {
const entity = await this.learningRecordRepo.findOne({ where: { id } });
if (!entity) throw new NotFoundException('学习记录不存在');
Object.assign(entity, dto);
@@ -225,4 +224,3 @@ export class ArchiveService {
return { message: '已删除' };
}
}