/** * API для работы с интерактивными досками */ import apiClient from '@/lib/api-client'; import { getLesson } from './schedule'; export interface Board { board_id: string; title: string; description?: string; access_type?: string; mentor?: number; student?: number; is_active?: boolean; created_at?: string; updated_at?: string; } /** * Одна доска на пару ментор–студент (сохраняется между уроками). * Атомарно получить существующую или создать новую. */ export async function getOrCreateMentorStudentBoard(mentorId: number, studentId: number): Promise { const res = await apiClient.get( `/board/boards/get-or-create-mentor-student/?mentor=${mentorId}&student=${studentId}` ); return res.data; } /** * Получить или создать доску для занятия. * Доска привязана к паре ментор–студент, а не к уроку: одна и та же доска для всех уроков этой пары. */ export async function getOrCreateLessonBoard(lessonId: number): Promise { const lesson = await getLesson(String(lessonId)); const mentorId = typeof lesson.mentor === 'object' && lesson.mentor ? Number(lesson.mentor.id) : Number(lesson.mentor); let studentId = 0; const c = lesson.client; if (c && typeof c === 'object') { if (c.user && typeof c.user === 'object') { studentId = Number(c.user.id); } else if ('user' in c && c.user) { const user = c.user as any; studentId = typeof user === 'object' ? Number(user.id) : Number(user); } else { studentId = Number((c as any).id ?? c); } } if (!mentorId || !studentId) throw new Error('Не удалось получить mentor и student из урока'); return getOrCreateMentorStudentBoard(mentorId, studentId); }