Private
Public Access
feat: hecho filtro de busqueda para los logs
This commit is contained in:
1 parent
1c0da9d70f
commit
a25afa1750
12 files changed
+288
-57
No files matched your search
@@ -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 };
|
||||
}
|
||||
@@ -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()}`
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user