All files / src/api course.api.ts

0% Statements 0/27
0% Branches 0/1
0% Functions 0/1
0% Lines 0/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61                                                                                                                         
import api from './axios'
import type { Course, CourseWithUsers, CourseCreate, CourseUpdate, User } from '@/types'
 
// ----------------------------------------------------------------
// COURSE API
// ----------------------------------------------------------------
export const courseApi = {
  /**
   * Get all courses
   */
  list: (skip = 0, limit = 100) => {
    return api.get<Course[]>('/courses/', { params: { skip, limit } })
  },
 
  /**
   * Get course by ID with users
   */
  getById: (courseId: string) => {
    return api.get<CourseWithUsers>(`/courses/${courseId}`)
  },
 
  /**
   * Create course (TEACHER/ADMIN only)
   */
  create: (data: CourseCreate) => {
    return api.post<Course>('/courses/', data)
  },
 
  /**
   * Update course (TEACHER/ADMIN only)
   */
  update: (courseId: string, data: CourseUpdate) => {
    return api.put<Course>(`/courses/${courseId}`, data)
  },
 
  /**
   * Delete course (TEACHER/ADMIN only)
   */
  delete: (courseId: string) => {
    return api.delete(`/courses/${courseId}`)
  },
 
  // --------------------------------------------------------------
  // MEMBERS
  // --------------------------------------------------------------
  // Members live on ``users.courseId`` server-side, so "list/add/remove"
  // map onto a thin REST surface under ``/courses/{id}/users``.
  listMembers: (courseId: string) => {
    return api.get<User[]>(`/courses/${courseId}/users`)
  },
 
  /** Add a batch of user-ids to ``courseId``. Returns the updated roster. */
  addMembers: (courseId: string, userIds: string[]) => {
    return api.post<User[]>(`/courses/${courseId}/users`, { userIds })
  },
 
  removeMember: (courseId: string, userId: string) => {
    return api.delete(`/courses/${courseId}/users/${userId}`)
  },
}