File size: 1,076 Bytes
6aa6081
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import api from './api';
import type { Section, PaginatedResponse } from '../types';

export async function listSections(filters: { page?: number; per_page?: number; search?: string; subject_id?: number; level?: string; academic_period?: string; student_name?: string; teacher_name?: string } = {}): Promise<PaginatedResponse<Section>> {
  const params = new URLSearchParams();
  Object.entries(filters).forEach(([k, v]) => { if (v !== undefined && v !== '') params.set(k, String(v)); });
  const { data } = await api.get(`/sections?${params}`);
  return data;
}

export async function createSection(payload: { name: string; subject_ids?: number[]; academic_period?: string; max_students?: number }): Promise<Section> {
  const { data } = await api.post('/sections', payload);
  return data;
}

export async function updateSection(id: number, payload: Partial<Section>): Promise<Section> {
  const { data } = await api.put(`/sections/${id}`, payload);
  return data;
}

export async function deleteSection(id: number): Promise<void> {
  await api.delete(`/sections/${id}`);
}