feat: hecho filtro de busqueda para los logs

This commit is contained in:
fede committed 2026-07-20 21:30:40 -03:00
1 parent 1c0da9d70f
commit a25afa1750
12 files changed
+288 -57

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
import { API_URL } from '$lib/env';
import type { RespuestaPagina } from '../../../routes/logs/LogsEstado.svelte';
import type { BusquedaLogsDto, LogEntry } from '../../../types';
import { getToken } from '../token';
export async function busquedaLogs(
pagina: number,
filtros: BusquedaLogsDto,
fetch2: Function
): Promise<RespuestaPagina<LogEntry> | { error: string }> {
const fetchFn = fetch2 ? fetch2 : fetch;
const res = await fetchFn(`${API_URL}/logs/${pagina}/busqueda`, {
method: 'POST',
headers: {
Authorization: `Bearer ${getToken()}`
},
body: JSON.stringify(filtros)
});
const data = await res.json();
if (!res.ok) {
return { error: data.error };
}
const totalPages = Math.ceil(data.maxlenght / 10);
return { logs: data.logs, maxPagina: Math.max(0, totalPages - 1), totalItems: data.maxlenght };
}
+6 -2
View File
@@ -3,8 +3,12 @@ import type { RespuestaPagina } from '../../../routes/logs/LogsEstado.svelte';
import type { LogEntry } from '../../../types';
import { getToken } from '../token';
export async function obtenerLogs(pagina: number): Promise<RespuestaPagina<LogEntry>> {
const res = await fetch(`${API_URL}/logs/${pagina}/`, {
export async function obtenerLogs(
pagina: number,
fetch2: Function
): Promise<RespuestaPagina<LogEntry>> {
const fetchFn = fetch2 ? fetch2 : fetch;
const res = await fetchFn(`${API_URL}/logs/${pagina}/`, {
headers: {
Authorization: `Bearer ${getToken()}`
}