añadido editar y eliminar posts

This commit is contained in:
2025-11-25 19:15:46 -03:00
parent dd49f853b4
commit e39bbe7047
20 changed files with 490 additions and 31 deletions

View File

@@ -0,0 +1,29 @@
import { apiBase } from '@/stores/url';
import type { Post, PostResponseDto } from '../../types';
import { get } from 'svelte/store';
import { sesionStore } from '@/stores/usuario';
export async function updatePost(post: Post, callbackfn: Function, message: string) {
try {
const data = {
content: post.content,
imageUrl: post.imageUrl
};
const req = await fetch(get(apiBase) + `/api/posts/${post.id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
},
body: JSON.stringify(data)
});
if (req.ok) {
const newpost: PostResponseDto = await req.json();
callbackfn(newpost);
return;
}
message = 'Fallo al intentar modificar la publicación';
} catch {
message = 'No se pudo alcanzar el servidor';
}
}