Se agrego datastage
This commit is contained in:
39
src/api/datastage.js
Normal file
39
src/api/datastage.js
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
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);
|
||||
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 [];
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchDatastageDetail(id) {
|
||||
const res = await getWithAuth(`${API_BASE}${id}/`);
|
||||
if (!res.ok) throw new Error('Error al obtener detalle');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function createDatastage(data) {
|
||||
const res = await postWithAuth(API_BASE, data);
|
||||
if (!res.ok) throw new Error('Error al crear datastage');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function updateDatastage(id, data) {
|
||||
const res = await patchWithAuth(`${API_BASE}${id}/`, data);
|
||||
if (!res.ok) throw new Error('Error al actualizar datastage');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function deleteDatastage(id) {
|
||||
const res = await deleteWithAuth(`${API_BASE}${id}/`);
|
||||
if (!res.ok) throw new Error('Error al eliminar datastage');
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user