Private
Public Access
feat: hecho lo de actualizar usuario
This commit is contained in:
1 parent
d0949e2560
commit
3d8883cac6
7 files changed
+52
-36
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { API_URL } from '$lib/env';
|
||||
import type { Usuario } from '../../types';
|
||||
import { getToken } from './token';
|
||||
|
||||
export async function actualizarUsuario(dto: Partial<Usuario>) {
|
||||
if (dto.id <= 0 || !dto.email || !dto.name) return 'Faltan Datos';
|
||||
try {
|
||||
const req = await fetch(`${API_URL}/usuarios/${dto.id}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${getToken()}`
|
||||
},
|
||||
body: JSON.stringify(dto)
|
||||
});
|
||||
|
||||
let data = await req.json();
|
||||
if (!req.ok) {
|
||||
return data.error || 'Error';
|
||||
}
|
||||
invalidate('usuarios:load');
|
||||
return 'Ok';
|
||||
} catch {
|
||||
return 'No se pudo conectar con el servidor';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user