Solucion de paginacion de datastage
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user