Se soluciono autenticacion
This commit is contained in:
@@ -1,15 +1,9 @@
|
||||
import { fetchWithAuth, putWithAuth } from '../fetchWithAuth';
|
||||
|
||||
// PUT para marcar una notificación como vista
|
||||
export async function marcarNotificacionComoVista(id: number): Promise<Notificacion> {
|
||||
const token = localStorage.getItem('access');
|
||||
const url = `${API_URL}/notificaciones/notificaciones/${id}/`;
|
||||
const headers = new Headers();
|
||||
if (token) headers.append('Authorization', `Bearer ${token}`);
|
||||
headers.append('Content-Type', 'application/json');
|
||||
const res = await fetch(url, {
|
||||
method: 'PUT',
|
||||
headers,
|
||||
body: JSON.stringify({ visto: true })
|
||||
});
|
||||
const res = await putWithAuth(url, { visto: true });
|
||||
if (!res.ok) throw new Error('Error al actualizar notificación');
|
||||
return await res.json();
|
||||
}
|
||||
@@ -41,28 +35,16 @@ export interface NotificacionesResponse {
|
||||
const API_URL = import.meta.env.VITE_EFC_API_URL;
|
||||
|
||||
export async function fetchNotificaciones({ page = 1, pageSize = 10, visto = false } = {}): Promise<NotificacionesResponse> {
|
||||
const token = localStorage.getItem('access');
|
||||
const url = `${API_URL}/notificaciones/notificaciones/?page=${page}&page_size=${pageSize}&visto=${visto}`;
|
||||
const headers = new Headers();
|
||||
if (token) headers.append('Authorization', `Bearer ${token}`);
|
||||
headers.append('Content-Type', 'application/json');
|
||||
const res = await fetch(url, {
|
||||
headers,
|
||||
});
|
||||
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<NotificacionesResponse>{
|
||||
const token = localStorage.getItem('access');
|
||||
const url = `${API_URL}/notificaciones/notificaciones/?page=${page}&page_size=${page_size}`;
|
||||
const headers = new Headers();
|
||||
if (token) headers.append('Authorization', `Bearer ${token}`);
|
||||
headers.append('Content-Type', 'application/json');
|
||||
const res = await fetch(url, {
|
||||
headers,
|
||||
});
|
||||
const res = await fetchWithAuth(url);
|
||||
if (!res.ok) throw new Error('Error al obtener notificaciones');
|
||||
return await res.json();
|
||||
}
|
||||
Reference in New Issue
Block a user