fc684e7c7d
- Миграция 005: user_id в test_attempts (дефолт 1 = Гость) - GET /api/attempts с фильтрами по тесту, дате и пагинацией - Страница /tracker: таблица попыток, фильтры, пагинация - Ссылка «Трекер» в шапке приложения Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
102 lines
2.1 KiB
TypeScript
102 lines
2.1 KiB
TypeScript
import client from './client'
|
|
|
|
export interface AnswerForTest {
|
|
id: number
|
|
text: string
|
|
}
|
|
|
|
export interface QuestionForTest {
|
|
id: number
|
|
text: string
|
|
is_multiple: boolean // true → показываем чекбоксы, false → радио-кнопки
|
|
answers: AnswerForTest[]
|
|
}
|
|
|
|
export interface AttemptStarted {
|
|
id: number
|
|
test_id: number
|
|
test_title: string
|
|
test_description: string | null
|
|
started_at: string
|
|
time_limit: number | null // минуты
|
|
allow_navigation_back: boolean
|
|
questions: QuestionForTest[]
|
|
}
|
|
|
|
export interface QuestionAnswer {
|
|
question_id: number
|
|
answer_ids: number[]
|
|
}
|
|
|
|
export interface AnswerResult {
|
|
id: number
|
|
text: string
|
|
is_correct: boolean
|
|
is_selected: boolean
|
|
}
|
|
|
|
export interface QuestionResult {
|
|
id: number
|
|
text: string
|
|
is_answered_correctly: boolean
|
|
answers: AnswerResult[]
|
|
}
|
|
|
|
export interface AttemptResult {
|
|
id: number
|
|
test_id: number
|
|
test_title: string
|
|
started_at: string
|
|
finished_at: string
|
|
score: number
|
|
passed: boolean
|
|
passing_score: number
|
|
correct_count: number
|
|
total_count: number
|
|
questions: QuestionResult[]
|
|
}
|
|
|
|
export interface AttemptListItem {
|
|
id: number
|
|
test_id: number
|
|
test_title: string
|
|
test_version: number
|
|
user_id: number
|
|
user_name: string
|
|
started_at: string
|
|
finished_at: string | null
|
|
score: number | null
|
|
correct_count: number | null
|
|
total_count: number | null
|
|
passed: boolean | null
|
|
}
|
|
|
|
export interface AttemptListResponse {
|
|
items: AttemptListItem[]
|
|
total: number
|
|
page: number
|
|
page_size: number
|
|
}
|
|
|
|
export interface AttemptListParams {
|
|
test_id?: number
|
|
date_from?: string
|
|
date_to?: string
|
|
page?: number
|
|
page_size?: number
|
|
}
|
|
|
|
export const attemptsApi = {
|
|
start: (test_id: number) =>
|
|
client.post<AttemptStarted>('/attempts', { test_id }),
|
|
|
|
submit: (attempt_id: number, answers: QuestionAnswer[]) =>
|
|
client.post<AttemptResult>(`/attempts/${attempt_id}/submit`, { answers }),
|
|
|
|
getResult: (attempt_id: number) =>
|
|
client.get<AttemptResult>(`/attempts/${attempt_id}/result`),
|
|
|
|
list: (params: AttemptListParams = {}) =>
|
|
client.get<AttemptListResponse>('/attempts', { params }),
|
|
}
|