fix: harden school imports and add optional feedback diagnostics
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user