32 lines
894 B
JavaScript
32 lines
894 B
JavaScript
/**
|
|
* Service for fetching real-time store connectivity status
|
|
*/
|
|
|
|
const API_URL = import.meta.env.VITE_API_URL;
|
|
|
|
/**
|
|
* Fetch store status from the backend
|
|
* @param {string} clientId - Client ID (2 for Peru, 3 for Colombia)
|
|
* @returns {Promise<Array>} Array of store status objects
|
|
*/
|
|
export const fetchStoreStatus = async (clientId) => {
|
|
try {
|
|
const url = `${API_URL}/stores/status?filter=all&id_cliente=${clientId}`;
|
|
|
|
const response = await fetch(url);
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP Error: ${response.status}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
|
|
// Return the stores array from the response
|
|
return data.stores || [];
|
|
} catch (error) {
|
|
console.error('Error fetching store status:', error);
|
|
// Return empty array on error to prevent breaking the UI
|
|
return [];
|
|
}
|
|
};
|