Просмотр исходного кода

refactor(speaking): hoist import and reuse parse helper in services

jimmylee 2 месяцев назад
Родитель
Сommit
a3daf8ea93
1 измененных файлов с 3 добавлено и 7 удалено
  1. 3 7
      src/services/speaking.ts

+ 3 - 7
src/services/speaking.ts

@@ -1,5 +1,5 @@
 import type { TopicDiscussionConfig } from '@/types/englishSpeaking'
-import { SPEAKING_CONFIG_API_BASE_URL } from '@/views/Editor/EnglishSpeaking/services/speakingApiConfig'
+import { SPEAKING_CONFIG_API_BASE_URL, SPEAKING_DIALOGUE_API_BASE_URL } from '@/views/Editor/EnglishSpeaking/services/speakingApiConfig'
 
 const API_BASE = SPEAKING_CONFIG_API_BASE_URL
 
@@ -49,8 +49,6 @@ export async function updateSpeakingConfig(
   return parse<SpeakingConfigRecord>(res)
 }
 
-import { SPEAKING_DIALOGUE_API_BASE_URL } from '@/views/Editor/EnglishSpeaking/services/speakingApiConfig'
-
 const DIALOGUE_BASE = SPEAKING_DIALOGUE_API_BASE_URL
 
 export interface ClassSessionSummary {
@@ -81,8 +79,7 @@ export async function listSpeakingSessionsByConfig(
     method: 'GET',
     credentials: 'include',
   })
-  if (!res.ok) throw new Error(`listSpeakingSessionsByConfig failed: ${res.status}`)
-  return res.json()
+  return parse<ListSessionsByConfigResponse>(res)
 }
 
 export interface ClassSummaryResponse {
@@ -103,6 +100,5 @@ export async function generateClassSummary(
     credentials: 'include',
     body: JSON.stringify({ configId, userIds, locale }),
   })
-  if (!res.ok) throw new Error(`generateClassSummary failed: ${res.status}`)
-  return res.json()
+  return parse<ClassSummaryResponse>(res)
 }