Files
Repuestera/front/src/lib/hooks/crearPermiso.ts
T
2026-05-11 22:43:45 -03:00

24 lines
711 B
TypeScript

import type { Permiso } 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.message || 'Error en la petición');
}
return response.json();
}
export async function crearPermiso(data: Partial<Permiso>): Promise<Permiso> {
const response = await fetch(`${API_URL}/permisos`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${getToken()}`
},
body: JSON.stringify(data)
});
return handleResponse<Permiso>(response);
}