40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { getAuthHeaders } from '@/api/auth'
|
|
|
|
const BASE_URL = import.meta.env.VITE_API_URL + '/classroom-compliance'
|
|
|
|
export interface Class {
|
|
id: number
|
|
number: number
|
|
schoolYear: string
|
|
}
|
|
|
|
export async function createClass(
|
|
auth: string,
|
|
number: number,
|
|
schoolYear: string,
|
|
): Promise<Class> {
|
|
const response = await fetch(BASE_URL + '/classes', {
|
|
method: 'POST',
|
|
headers: getAuthHeaders(auth),
|
|
body: JSON.stringify({ number: number, schoolYear: schoolYear }),
|
|
})
|
|
return (await response.json()) as Class
|
|
}
|
|
|
|
export async function getClasses(auth: string): Promise<Class[]> {
|
|
const response = await fetch(BASE_URL + '/classes', {
|
|
headers: getAuthHeaders(auth),
|
|
})
|
|
return (await response.json()) as Class[]
|
|
}
|
|
|
|
export async function deleteClass(auth: string, classId: number): Promise<void> {
|
|
const response = await fetch(BASE_URL + '/classes/' + classId, {
|
|
method: 'DELETE',
|
|
headers: getAuthHeaders(auth),
|
|
})
|
|
if (!response.ok) {
|
|
throw new Error('Failed to delete class.')
|
|
}
|
|
}
|