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) { if (!dto.id || 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'; } }