mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-28 17:22:47 -03:00
snashot de como tenia las cosas cuando fallaba la invalidacion de ruta
This commit is contained in:
@@ -1,48 +1,50 @@
|
||||
import { apiBase } from "@/stores/url"
|
||||
import { sesionStore } from "@/stores/usuario"
|
||||
import { get } from "svelte/store"
|
||||
import { apiBase } from '@/stores/url';
|
||||
import { sesionStore } from '@/stores/usuario';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
export interface AdminUpdateUsuario {
|
||||
id:string,
|
||||
displayName: string | null,
|
||||
bio: string | null,
|
||||
profileImage:boolean,
|
||||
image:File,
|
||||
profileImageUrl:string|null
|
||||
id: string;
|
||||
displayName: string | null;
|
||||
bio: string | null;
|
||||
profileImage: boolean;
|
||||
image: File;
|
||||
profileImageUrl: string | null;
|
||||
}
|
||||
|
||||
export async function updateUsuario(usuario: Partial<AdminUpdateUsuario>) {
|
||||
const formData = new FormData();
|
||||
if (usuario.displayName) formData.append('displayName', usuario.displayName);
|
||||
if (usuario.bio) formData.append('bio', usuario.bio);
|
||||
if (usuario.profileImage) {
|
||||
if (usuario.profileImageUrl) formData.append('profileImageUrl', 'null');
|
||||
} else {
|
||||
if (usuario.profileImageUrl) {
|
||||
formData.append('profileImageUrl', usuario.profileImageUrl);
|
||||
} else {
|
||||
if (usuario.image) formData.append('profileImage', usuario.image);
|
||||
}
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
if (usuario.displayName) formData.append('displayName', usuario.displayName);
|
||||
if (usuario.bio) formData.append('bio', usuario.bio);
|
||||
if (usuario.image) formData.append('profileImage', usuario.image);
|
||||
if (usuario.profileImage){
|
||||
if (usuario.profileImageUrl) formData.append('profileImageUrl', 'null');
|
||||
}else{
|
||||
if (usuario.profileImageUrl) formData.append('profileImageUrl', usuario.profileImageUrl);
|
||||
}
|
||||
try {
|
||||
const req = await fetch(get(apiBase) + '/api/users/' + usuario.id, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
|
||||
},
|
||||
body: formData
|
||||
});
|
||||
if (req.status === 204) {
|
||||
let ret = {
|
||||
// bio: usuario.bio,
|
||||
displayName: usuario.displayName
|
||||
// oldImageUrl: usuario.oldImageUrl,
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
const dataa = await req.json();
|
||||
|
||||
try {
|
||||
const req = await fetch(get(apiBase) + "/api/users/"+usuario.id, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
|
||||
},
|
||||
body: formData,
|
||||
});
|
||||
if (req.status === 204) {
|
||||
let ret = {
|
||||
// bio: usuario.bio,
|
||||
displayName: usuario.displayName,
|
||||
// oldImageUrl: usuario.oldImageUrl,
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
const dataa = await req.json();
|
||||
|
||||
return dataa.message;
|
||||
} catch {
|
||||
return "No se pudo alcanzar el servidor"
|
||||
}
|
||||
return dataa.message;
|
||||
} catch {
|
||||
return 'No se pudo alcanzar el servidor';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user