mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-04 13:40:43 -03:00
23 lines
672 B
TypeScript
23 lines
672 B
TypeScript
import { apiBase } from '@/stores/url';
|
|
import { get } from 'svelte/store';
|
|
import { sesionStore } from '@/stores/usuario';
|
|
import type { Post } from '../../types';
|
|
|
|
export async function likePost(post: Post) {
|
|
let method = post.isLiked ? "DELETE" : "POST";
|
|
try {
|
|
const req = await fetch(get(apiBase) + `/api/posts/${post.id}/like`, {
|
|
method: method,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
|
|
}
|
|
});
|
|
|
|
const data: { message: string } = await req.json();
|
|
return { message: data.message, ok: req.ok };
|
|
} catch {
|
|
return { message: 'No se pudo alcanzar el servidor', ok: false };
|
|
}
|
|
}
|