修复复盘保存失败:原地更新成绩并新增 review 专用接口。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -120,6 +120,10 @@ export const examApi = {
|
||||
examId: string,
|
||||
data: Partial<{ exam_type: ExamType; exam_date: string; title: string; scores: ScoreInput[] }>,
|
||||
) => api.patch<Exam>(`/exams/${examId}`, data),
|
||||
updateReview: (
|
||||
examId: string,
|
||||
reviews: { subject_id: number; review_statuses: ScoreInput['review_statuses'] }[],
|
||||
) => api.patch<Exam>(`/exams/${examId}/review`, { reviews }),
|
||||
remove: (examId: string) => api.delete(`/exams/${examId}`),
|
||||
trend: (studentId: string, subjectId: number) =>
|
||||
api.get<TrendResponse>(`/students/${studentId}/scores/trend`, {
|
||||
|
||||
@@ -5,6 +5,17 @@ import type { Exam, ReviewStatus } from '../types'
|
||||
import { EXAM_TYPE_LABELS, REVIEW_STATUS_OPTIONS } from '../types'
|
||||
import ReviewTreeChart from './ReviewTreeChart'
|
||||
|
||||
function apiErrorMessage(err: unknown, fallback: string): string {
|
||||
if (err && typeof err === 'object' && 'response' in err) {
|
||||
const detail = (err as { response?: { data?: { detail?: unknown } } }).response?.data?.detail
|
||||
if (typeof detail === 'string') return detail
|
||||
if (Array.isArray(detail)) {
|
||||
return detail.map((item) => item?.msg || String(item)).join(';')
|
||||
}
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
interface Props {
|
||||
exams: Exam[]
|
||||
onRefresh: () => void
|
||||
@@ -53,18 +64,17 @@ export default function ExamReviewPanel({ exams, onRefresh }: Props) {
|
||||
}
|
||||
setSaving(true)
|
||||
try {
|
||||
await examApi.update(selectedExam.id, {
|
||||
scores: selectedExam.scores.map((score) => ({
|
||||
await examApi.updateReview(
|
||||
selectedExam.id,
|
||||
selectedExam.scores.map((score) => ({
|
||||
subject_id: score.subject_id,
|
||||
total_score: score.total_score,
|
||||
obtained_score: score.obtained_score,
|
||||
review_statuses: statusMap[score.subject_id] || [],
|
||||
})),
|
||||
})
|
||||
)
|
||||
message.success('复盘已保存')
|
||||
onRefresh()
|
||||
} catch {
|
||||
message.error('保存失败')
|
||||
} catch (err) {
|
||||
message.error(apiErrorMessage(err, '保存失败'))
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user