import { fetchWithAuth, putWithAuth } from '../fetchWithAuth'; // PUT para marcar una notificación como vista export async function marcarNotificacionComoVista(id: number): Promise { const url = `${API_URL}/notificaciones/notificaciones/${id}/`; const res = await putWithAuth(url, { visto: true }); if (!res.ok) throw new Error('Error al actualizar notificación'); return await res.json(); } // src/api/notificaciones.ts export interface TipoNotificacion { id: number; tipo: string; descripcion: string; } export interface NotificacionDatos { task_id: string; label: string; resultado: Record; } export interface Notificacion { id: number; tipo: TipoNotificacion; dirigido: string; mensaje: string; datos: NotificacionDatos | null; fecha_envio: string; created_at: string; visto: boolean; } export interface NotificacionesResponse { count: number; next: string | null; previous: string | null; results: Notificacion[]; } const API_URL = import.meta.env.VITE_EFC_API_URL; export async function fetchNotificaciones({ page = 1, pageSize = 10, visto = false } = {}): Promise { const url = `${API_URL}/notificaciones/notificaciones/?page=${page}&page_size=${pageSize}&visto=${visto}`; const res = await fetchWithAuth(url); if (!res.ok) throw new Error('Error al obtener notificaciones'); return await res.json(); } export async function fetchAllNotifications({page = 1, page_size=10}): Promise{ const url = `${API_URL}/notificaciones/notificaciones/?page=${page}&page_size=${page_size}`; const res = await fetchWithAuth(url); if (!res.ok) throw new Error('Error al obtener notificaciones'); return await res.json(); } export async function fetchNotificacionByTaskId(taskId: string): Promise { const url = `${API_URL}/notificaciones/notificaciones/by-task/${taskId}/`; const res = await fetchWithAuth(url); if (res.status === 404) return null; if (!res.ok) throw new Error('Error al obtener notificación por task_id'); return await res.json(); }