Private
Public Access
feat: implementado skeleton de la pagina de gestion de usuarios
This commit is contained in:
1 parent
5fb1bbeb94
commit
e70813c4d0
9 files changed
+95
-34
No files matched your search
@@ -1,6 +1,5 @@
|
||||
export { login } from './hooks/login';
|
||||
export { register } from './hooks/register';
|
||||
export { obtenerUsuarios } from './hooks/obtenerUsuarios';
|
||||
export { obtenerUsuarioPorId } from './hooks/obtenerUsuarioPorId';
|
||||
export { modificarUsuario } from './hooks/modificarUsuario';
|
||||
export { borrarUsuario } from './hooks/borrarUsuario';
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
export 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();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { API_URL } from '$lib/env';
|
||||
import { handleResponse } from '$lib/handleRespondeJSON';
|
||||
import type { Usuario } from '../../types';
|
||||
import { getToken } from './token';
|
||||
|
||||
export async function ObtenerUsuarios(tamaño: number, pagina: number, fetch2?: Function) {
|
||||
let fetchfn = fetch2 ? fetch2 : fetch;
|
||||
const req = await fetchfn(`${API_URL}/usuarios?p=${pagina}&s=${tamaño}`, {
|
||||
headers: { Authorization: `Bearer ${getToken()}` }
|
||||
});
|
||||
return handleResponse<Usuario[]>(req);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import type { Usuario } 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 obtenerUsuarios(): Promise<Usuario[]> {
|
||||
const response = await fetch(`${API_URL}/users`, {
|
||||
headers: { Authorization: `Bearer ${getToken()}` }
|
||||
});
|
||||
return handleResponse<Usuario[]>(response);
|
||||
}
|
||||
Reference in new issue
Block a user