fix: harden school imports and add optional feedback diagnostics

This commit is contained in:
Codex
2026-10-15 10:37:32 +08:00
parent 674df1ceb3
commit 7299f4d8b6
25 changed files with 722 additions and 42 deletions
+7 -2
View File
@@ -46,6 +46,10 @@ class ExamRecord {
return value;
}
final typeId = json['examTypeId'];
if (typeId != null && (typeId is! int || typeId < 1 || typeId > 3)) {
throw const FormatException('考试类型无效');
}
final record = ExamRecord(
code: field('code'),
name: field('name'),
@@ -58,7 +62,7 @@ class ExamRecord {
date: field('date', optional: true),
status: field('status', optional: true),
notes: field('notes', optional: true),
examTypeId: json['examTypeId'] as int?,
examTypeId: typeId as int?,
);
if (record.code.isEmpty || record.name.isEmpty) {
throw const FormatException('考试课程无效');
@@ -107,7 +111,8 @@ class ExamSchedule {
? SupportedSchool.uestcGraduate
: SupportedSchool.fromId(json['schoolId'] as String);
final rawTypes = json['requestedExamTypes'] ?? <int>[];
if (rawTypes is! List || rawTypes.any((t) => t is! int || t < 1 || t > 3)) {
if (rawTypes is! List ||
rawTypes.any((t) => t is! int || t < 1 || t > 3)) {
throw const FormatException('考试类型无效');
}
final types = rawTypes.cast<int>().toSet();