Private
Public Access
19 lines
592 B
TypeScript
19 lines
592 B
TypeScript
import type { Grupo } from '../../types';
|
|
import { API_URL } from '../env';
|
|
import { getToken } from './token';
|
|
|
|
async function handleResponse<T>(response: Response): Promise<T> {
|
|
if (!response.ok) {
|
|
const error = await response.json().catch(() => ({ message: 'Error desconocido' }));
|
|
throw new Error(error.error || 'Error en la petición');
|
|
}
|
|
return response.json();
|
|
}
|
|
|
|
export async function obtenerGrupos(): Promise<Grupo[]> {
|
|
const response = await fetch(`${API_URL}/grupos`, {
|
|
headers: { Authorization: `Bearer ${getToken()}` }
|
|
});
|
|
return handleResponse<Grupo[]>(response);
|
|
}
|