Spaces:
Runtime error
Runtime error
Download frontend/src/services/teacherService.ts from Talosware/talos-access: direct link, hf CLI and curl.
- Browser
- Download file 5.83 kB
-
https://huggingface.co/spaces/Talosware/talos-access/resolve/main/frontend/src/services/teacherService.ts
- Command line
-
hf download hf://spaces/Talosware/talos-access/frontend/src/services/teacherService.ts
-
curl -L -o teacherService.ts https://huggingface.co/spaces/Talosware/talos-access/resolve/main/frontend/src/services/teacherService.ts
5.83 kB
| import api from './api'; | |
| export interface TeacherSection { | |
| id: number; | |
| name: string; | |
| subject_id?: number | null; | |
| subject_name: string | null; | |
| subjects?: { subject_id: number; subject_name: string | null }[]; | |
| academic_period: string | null; | |
| student_count: number; | |
| today_schedule: { | |
| day: number; | |
| blocks: { | |
| id: number; | |
| entry_time: string; | |
| exit_time: string; | |
| subject_id: number | null; | |
| status: 'active' | 'upcoming' | 'passed' | 'inactive'; | |
| }[]; | |
| } | null; | |
| } | |
| export interface StudentCard { | |
| id: number; | |
| name: string; | |
| lastname: string; | |
| card_id: string | null; | |
| phone_number: string | null; | |
| already_checked_in: boolean; | |
| } | |
| export interface PresentSummary { | |
| masculino: number; | |
| femenino: number; | |
| sin_especificar: number; | |
| total: number; | |
| } | |
| export interface SwipeResult { | |
| created: number; | |
| total: number; | |
| /** Students that were swiped present but couldn't be marked because they | |
| * haven't done their gate check-in (EntranceLog) for today. */ | |
| skipped: { student_id: number; name: string }[]; | |
| present_today?: PresentSummary; | |
| } | |
| export interface AttendanceSummaryItem { | |
| student_id: number; | |
| student_name: string; | |
| student_lastname: string; | |
| card_id: string | null; | |
| phone_number: string | null; | |
| present: boolean; | |
| attendance_id: number | null; | |
| parent_name: string | null; | |
| parent_phone: string | null; | |
| } | |
| export interface ToggleResult { | |
| present: boolean; | |
| attendance_id: number | null; | |
| } | |
| export interface TeacherSubject { | |
| id: number; | |
| name: string; | |
| code: string | null; | |
| description: string | null; | |
| sections: TeacherSection[]; | |
| } | |
| export interface StudentProfile { | |
| student: { id: number; name: string; lastname: string; card_id: string | null; phone_number: string | null; email: string | null; }; | |
| parent: { name: string; phone: string } | null; | |
| attendance_history: { date: string; present: boolean }[]; | |
| total_records: number; | |
| } | |
| export interface ScheduleBlock { | |
| id: number; | |
| section_id: number; | |
| section_name: string | null; | |
| day_of_week: number; | |
| entry_time: string; | |
| exit_time: string; | |
| subject_id: number | null; | |
| subject_name: string | null; | |
| } | |
| export interface TeacherSchedule { | |
| today: ScheduleBlock[]; | |
| week: ScheduleBlock[]; | |
| } | |
| export async function getTeacherSections(): Promise<TeacherSection[]> { | |
| const { data } = await api.get('/teacher/sections'); | |
| return data; | |
| } | |
| export async function getTeacherSubjects(): Promise<TeacherSubject[]> { | |
| const { data } = await api.get('/teacher/subjects'); | |
| return data; | |
| } | |
| export async function getSectionStudents(sectionId: number): Promise<StudentCard[]> { | |
| const { data } = await api.get(`/teacher/sections/${sectionId}/students`); | |
| return data; | |
| } | |
| export async function submitSwipeAttendance( | |
| sectionId: number, | |
| records: { student_id: number; present: boolean }[], | |
| subjectId?: number | null | |
| ): Promise<SwipeResult> { | |
| const { data } = await api.post('/teacher/attendance/swipe', { section_id: sectionId, subject_id: subjectId || undefined, records }); | |
| return data; | |
| } | |
| export async function getAttendanceSummary(sectionId: number, dateStr?: string): Promise<AttendanceSummaryItem[]> { | |
| const params: any = { section_id: sectionId }; | |
| if (dateStr) params.date = dateStr; | |
| const { data } = await api.get('/teacher/attendance-summary', { params }); | |
| return data; | |
| } | |
| export async function toggleAttendance(sectionId: number, studentId: number, dateStr?: string, subjectId?: number | null): Promise<ToggleResult> { | |
| const params: any = { section_id: sectionId, student_id: studentId, subject_id: subjectId || undefined }; | |
| if (dateStr) params.date = dateStr; | |
| const { data } = await api.put('/teacher/attendance/toggle', null, { params }); | |
| return data; | |
| } | |
| export async function getStudentProfile(studentId: number): Promise<StudentProfile> { | |
| const { data } = await api.get(`/teacher/students/${studentId}/profile`); | |
| return data; | |
| } | |
| export async function downloadAttendanceCSV(sectionId: number, dateStr?: string): Promise<void> { | |
| const { data } = await api.get('/teacher/attendance-export', { | |
| params: { section_id: sectionId, date: dateStr, dateStr: undefined }, | |
| responseType: 'blob', | |
| }); | |
| const url = URL.createObjectURL(data); | |
| const a = document.createElement('a'); a.href = url; a.download = `asistencia_${sectionId}_${dateStr || new Date().toISOString().slice(0, 10)}.csv`; a.click(); | |
| URL.revokeObjectURL(url); | |
| } | |
| export interface BatchToggleResult { | |
| skipped: { student_id: number; name: string }[]; | |
| present_today?: PresentSummary; | |
| } | |
| export async function batchToggleAttendance( | |
| sectionId: number, | |
| records: { student_id: number; present: boolean }[], | |
| subjectId?: number | null, | |
| dateStr?: string | |
| ): Promise<BatchToggleResult> { | |
| const params: any = {}; | |
| if (dateStr) params.date = dateStr; | |
| const { data } = await api.post('/teacher/attendance/batch-toggle', { section_id: sectionId, subject_id: subjectId || undefined, records }, { params }); | |
| return data; | |
| } | |
| export async function getPresentSummary(sectionId: number, dateISO?: string): Promise<PresentSummary> { | |
| const params: any = {}; | |
| if (dateISO) params.date = dateISO; | |
| const { data } = await api.get(`/teacher/sections/${sectionId}/present-summary`, { params }); | |
| return data; | |
| } | |
| export async function getTeacherSchedule(): Promise<TeacherSchedule> { | |
| const { data } = await api.get('/teacher/schedule'); | |
| return data; | |
| } | |
| export async function downloadSubjectStudents(subjectId: number, subjectName: string): Promise<void> { | |
| const { data } = await api.get(`/teacher/subjects/${subjectId}/export`, { | |
| responseType: 'blob', | |
| }); | |
| const url = URL.createObjectURL(data); | |
| const a = document.createElement('a'); a.href = url; a.download = `export_${subjectName.replace(/\s+/g, '_')}.xlsx`; a.click(); | |
| URL.revokeObjectURL(url); | |
| } | |