Files
ember-market-frontend/lib/stats-service.ts
NotII 1bec653206 ugh
2025-03-28 22:56:57 +00:00

51 lines
1.1 KiB
TypeScript

export interface PlatformStats {
orders: {
completed: number;
};
vendors: {
total: number;
};
transactions: {
volume: number;
averageOrderValue: number;
};
}
export async function fetchPlatformStats(): Promise<PlatformStats> {
const BASE_API_URL = process.env.SERVER_API_URL || 'http://localhost:3001/api';
console.log('Fetching platform stats from:', BASE_API_URL);
try {
const response = await fetch(`${BASE_API_URL}/stats/platform`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
cache: 'no-store'
});
if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}
const data = await response.json();
console.log('Fetched stats:', data);
return data;
} catch (error) {
console.error('Error fetching platform stats:', error);
// Return fallback data if API fails
return {
orders: {
completed: 15800
},
vendors: {
total: 2400
},
transactions: {
volume: 3200000,
averageOrderValue: 220
}
};
}
}