Solucion de paginacion de datastage

This commit is contained in:
2025-08-22 23:48:26 -06:00
parent c401bb7889
commit 6309bc1b96
2 changed files with 25 additions and 17 deletions

View File

@@ -10,14 +10,12 @@ import.meta.env;
import { getWithAuth, postWithAuth, patchWithAuth, deleteWithAuth } from '../fetchWithAuth';
const API_BASE = `${import.meta.env.VITE_EFC_API_URL}/datastage/datastages/`;
export async function fetchDatastages() {
const res = await getWithAuth(API_BASE);
export async function fetchDatastages(page = 1, page_size = 10) {
const url = `${API_BASE}?page=${page}&page_size=${page_size}`;
const res = await getWithAuth(url);
if (!res.ok) throw new Error('Error al obtener datastages');
const data = await res.json();
// Si la respuesta es paginada, devolver results
if (data && Array.isArray(data.results)) return data.results;
// Si la respuesta no es un array, devolver array vacío
if (!Array.isArray(data)) return [];
// Si la respuesta es paginada, devolver el objeto completo
return data;
}